Can NetworkServer.Spawn() spawn a parent prefab with a bunch of child prefabs?

I’m just curious if NetworkServer.Spawn() can spawn in prefabs with child prefabs. And if it can, where in the documentations does it tell us how to spawn them?

I’ve been looking everywhere, and it’s giving me the impression that NetworkServer.Spawn() cannot spawn these parent prefabs. If I can get a confirmation, it would be nice to know.

From my experience…
So I have PlayerShip NetworkBehaviour built of several modules as child NetworkBehaviour.
I call spawn on PlayerShip - prefabs spawns on net with all children.
HOWEVER: modules don’t count as spawned by servers, so isLocalPlayer is always false, and so is isServer on those children. It gave me a quite of pain to find out what’s exactly causing my player not be able to control ship entirely.
Conclusion is, in order for it to function properly, you’ll need to handle spawning each prefab, at least for now. I hope Unity finds an out-of-the-box solution for this. For now I am waiting with my gameplay stuff till at least Unity 5.2, cause I’ll need clients to have multiple player objects. Meanwhile, I am working on different things, like hangar to pick modules etc.

If you spawn a nested prefab all of the child objects will be Instantiated on all connected clients. However if they have NetworkIdentities they will not be spawned to all connected clients. Meaning they will exist as local gameobjects everywhere but will have uninitialized network components. If you attempt to then spawn those children from the server you will get copies of those objects (that are network initialized).

Basically Spawn does not have any logic for recursion. One would sort of assume if I had a stack of objets with NetworkIdentities that if I spawned the top object it would also go through the spawning process for all the children with NetworkIdentities giving me what I would think of as a “fully initialized network object”. That doesn’t appear to be how it works. The HLAPI spawns the exact object tree you feed it and initializes the top level object on the network.

I ran into what I believe is the same issue

^ There’s the unity answers posts where I kinda figured out how to work around it.

2 Likes