The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How do you set the parent object of a PhotonNetwork.InstantiateSceneObject?

2016-12-01 17:19:38

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.


2016-12-02 11:38:43


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.



2016-12-02 19:47:46

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]); }

2016-12-06 23:33:15

Thanks for the info steamcore.

Back to top