BoltNetwork.Instantiate not working on modified prefabs?
I'm trying to instantiate a prefab with some changes (add mesh and material), and on host it is working correctly but on another client the changes are not shown (no mesh, no material).
prefab.GetComponent<MeshFilter>().mesh = someObject.GetComponent<MeshFilter>().mesh;
prefab.GetComponent<MeshRenderer>().material = someObject.GetComponent<MeshRenderer>().material;
prefab.GetComponent<MeshCollider>().sharedMesh = someObject.GetComponent<MeshCollider>().sharedMesh;
BoltNetwork.Instantiate(prefab, Vector3.zero, Random.rotation);
Answers
-
Hi,
All of your changes, in this case, are local only.
Bolt will only synchronize what is described on the State of the Entity associated with your prefab.
There is no hidden sync for materials or anything related to that if they are not explicitly declared on the State, so if you want that your prefab has a different appearance, you need to make the modifications on the Server and on the Client.
This can be done on the
EntityBehaviour.Attached
callback (https://doc-api.photonengine.com/en/bolt/current/class_photon_1_1_bolt_1_1_entity_behaviour.html#aa6f843bbe3bd8af6ca21e12ad1d28d0a) for example, that will run on each peer in which the entity is created.Also, if you want to pass some initial values to your Entity, you can use a
IProtocolToken
(https://doc.photonengine.com/en-us/bolt/current/in-depth/protocol-tokens) to send custom values, and pass it on to theBoltNetwork.Instantiate
(https://doc-api.photonengine.com/en/bolt/current/class_photon_1_1_bolt_1_1_bolt_network.html#a759b2f408a4615f6cea5c3c6ec8a1a00) and use it when theAttached
is invoked, like it's shown here: https://doc.photonengine.com/en-US/bolt/current/in-depth/Protocol-Tokens/#entity_instantiation_example--
Ramon Melo
Photon Bolt Team
0