Search Unity

Custom Spawn Functions - Pooling issue

Discussion in 'Connected Games' started by Doghelmer, Aug 25, 2018.

  1. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    112
    I have an issue at the moment that's driving me a bit nuts. I'm using the UNet Custom Spawns system detailed on this page to do object pooling on both the client and server.

    I'm registering the spawn handler to spawn items, as indicated on this page:
    itemAssetID = gc.spawnerMain.itemPrefab.GetComponent<NetworkIdentity>().assetId;
    ClientScene.RegisterSpawnHandler(itemAssetID, SpawnItemClient, UnSpawnItemClient);

    However, sometimes when I spawn an item on the server using NetworkServer.Spawn(), SpawnItemClient is called MULTIPLE times in succession. First, the item I want is spawned. Then, a couple of other items from the pool that had previously been spawned -- and subsequently unspawned using NetworkServer.UnSpawn() -- are spawned again.

    Any ideas on how a single NetworkServer.Spawn() call could possibly result in multiple spawns on the client like this? Is it possible that multiple items are somehow getting registered as one?
     
    Last edited: Aug 25, 2018
  2. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    112
    Found the source of the issue. It's a bit complicated, but for anyone else who might run into this, check to see that you're not calling NetworkIdentity.RebuildObservers() inappropriately
     
unityunity