Hi guys. I’m trying to do an objects pooling (for multiple prefab types) spawned via NetworkServer.Spawn but I’m stuck with this issue.
ClientScene.prefabs are out of sync when I register prefabs on the server and then try to join with a fresh client.
So I can’t get a prefab via assetId called in SpawnDelegate.
I’ve checked ClientScene.prefabs dictionary on client, and can confirm that they do not sync on fresh client join.
Do I have to sync prefabs (ClientScene.prefabs) manually before I join with the client somehow?
Or maybe there’s a way to load a prefab on a client via assetId (which I doubt exists)?
Also, I can’t just put prefabs on spawnable list in NetworkManager, because it overrides Spawn/UnSpawn delegates.
Any tips appreciated
Spawn/UnSpawn delegates snippet:
public delegate GameObject SpawnDelegate(Vector3 position, NetworkHash128 assetId);
public delegate void UnSpawnDelegate(GameObject spawned);
public void RegisterPrefab(GameObject unitPrefab, NetworkHash128 assetId) {
ClientScene.RegisterPrefab(unitPrefab, SpawnUnit, UnSpawnUnit);
}
private GameObject SpawnUnit(Vector3 position, NetworkHash128 assetid) {
GameObject prefab;
ClientScene.prefabs.TryGetValue(assetid, out prefab);
if (prefab == null) {
Debug.LogError("UnitPool:: SpawnUnit() - Unable to retrieve prefab by assetId");
}
return InstantiateFromUnitPool(prefab, position);
}
public void UnSpawnUnit(GameObject spawned) {
Debug.Log("Unspawning");
spawned.SetActive(false);
}