Proper way to Enable/Disable GameObjects on All Clients (Object Pooling)

I’m working out an object pooling system for a multiplayer game, and the cleanest way is to enable/disable the gameObject across the network. There are other ways, such as enabling/disabling certain scripts/components/behaviours.

Is enabling/disabling gameObjects that have NetworkIdentities supported by the HLAPI? I often get the warning “no free events for message” followed by a crash for the remote client.

I’ve tried ensuring the enabling/disabling happens on all clients at the same time by putting that logic in a ClientRpc.

Has anyone gotten this to work?

Hey,

did you tried to use NetworkServer.Spawn and NetworkServer.UnSpawn?
UnSpawn doesn’t destroys an object allowing you to reuse it again.

Maybe Unspawn() could work. Spawn() just sends a few variables and the actual instantiation occurs on each client?

Yes, Spawn() “asks” all ready clients to spawn specified object with server authority.
To spawn stuff with client authority use the NetworkServer.SpawnWithClientAuthority() API.

You also have these delegates to customize the Spawn and Unspawn behavior:
SpawnDelegate and UnSpawnDelegate

Thanks, not everything is so explicit in the documentation.

1 Like

Haven’t a clue what the id should be when using custom pooling.

Hi! I’m having an issue with not having an enabled object show across the server. Could you please look here and give me some ideas? THANKS! http://forum.unity3d.com/threads/how-to-sync-state-of-gameobject-in-the-unity-unet-multiplayer-system.388771/