- Home /
Question by
medvefd · Jun 29, 2014 at 05:18 AM ·
instantiatenetworkinitializationinitialize
Initializing an object on Network.Instantiate
I'm instantiating a prefab with Network.Instantiate and need to initialize one of my scripts on the instances on all clients. The problem is that my script needs to receive several GameObjects that are known on instance time. I can't write my init function and call it with Network.RPC because it can't accept GameObject parameters. Also I cant just assign them like this, since it will do it only for the client who instantiated the prefab:
instance = (GameObject)Network.Instantiate(prefab, transform.position, transform.rotation, 0);
myClass myScript = instance.GetComponent<myClass>();
myScript.attribute1 = gameObject;
Am I missing some obvious way to do it?
Comment
If the GameObject being assigned is client-dependent then you are out of luck, otherwise just fire an RPC to tell other clients to acquire the appropriate reference.
Your answer
![](https://koobas.hobune.stream/wayback/20220613152755im_/https://answers.unity.com/themes/thub/images/avi.jpg)