0
\$\begingroup\$

I want to instantiate an object on only the server and one client. This means Network.Instantiate is out of the question and I have to instantiate it manually. Since Network.Instantiate takes a prefab, there must be some way of identifying a prefab over a network( you can't send a reference in an rpc. ) How can I do this? Drag and dropping the prefab from the inspector is also not an option, since the component with this reference is on the server only( the client doesn't have a local reference. )

\$\endgroup\$
0
\$\begingroup\$

It turns out Resources.FindObjectsOfTypeAll where T is GameObject, returns all game objects "resources" in the project. In other words this gets all your prefabs. They do not have to be in a "Resources" folder.

Using this list I can now search them by some sort of ID( either assigned by me, or Unity ), then send that ID over the network and find the prefab from that locally.

The problem with this is that the prefab has to be "loaded" on both machines. It's reasonable to believe that if a prefab is loaded on the server, it should be loaded in the client. As long as there is some reference to the prefab in a script( through the inspector, direct or indirect ) or the prefab is explicitly loaded using Resources.Load, it will be able to be found this way.

Also, assets are always loaded in the editor. Don't be fooled by this. It does not mean the asset will be loaded in a build.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.