How do you set the parent object of a PhotonNetwork.InstantiateSceneObject?
Options
roskelld
✭
I've been populating my level with Instantiated scene objects, but no matter where I call the code from in the scene structure, the objects become children of the root.
How do I instantiate them as children of another scene object? I have data in the desired parent that I need them to inherit.
How do I instantiate them as children of another scene object? I have data in the desired parent that I need them to inherit.
0
Comments
-
Hi,
you'll have to do that on each instance yes, parenting is something you have to do manually because we can't pass a gameobject reference directly over the network.
so when a instance is spawned, either it is responsible to find its parent and attached itself to it, or else a manager has to watch for this objects and attached them appropriately.
Bye,
Jean
0 -
The way I do it is I instantiate the object and then immediately call an RPC called doEnable();
Within doEnable(), it picks up parent object, syncs itself with the game, etc. For instance each player has a different color each time you spawn. The game manager has a list of colors and keeps track of which color is correct, and then I call doEnable(int) right after instantiating. THe RPC comes through on everyone's client, and the method looks something like:[punRPC] public void doEnable (int playerColor) { meshRenderer.material.color = gameManager.colors[playerColor]; }
You could cache references to all the objects that will serve as parents in the gameManager, and then parent them in an RPC like[punRPC] public void doEnable (int parent) { transform.SetParent(gameManager.parentObjects[parent]); }
0 -
Thanks for the info steamcore.0