How can I send a prefab by RPC?
Right now, I am sending prefab’s as strings, and calling Resource.Load() on everyone that receives the RPC, but this is very inconvenient, because it forces me to keep all my prefabs in the resource folder, and also to manually type out the names of all the prefabs.
In the documentation for Network.Instantiate, it says that unity uses an “identifier” for the prefab and sends an RPC. Where exactly does this identifier come from?
Well, since presumably both computers already have the prefab (because it was packaged with the game), all you need to do is send a ‘signal’ RPC which includes a ‘NetworkViewID’- this will allow you to synchronise two objects, assuming that they are compatible.
When the signal RPC arrives, the receiver should spawn the correct prefab, and the assign the received NetworkViewID to the newly created object’s networkView.viewID field.
So, all you need to do is assign the prefabs in the inspector, like normal, and then just make sure that they have networkViews, and that the instantiation happens in an RPC call that knows what prefab to spawn. Remember that unless you change the references at some point (which is always going to be a problem for prefab instantiations), it will just work.