So I’m having the following issue after updating Netcode for gameobjects from 1.2.0 to 1.5.2:
Before, I would instantiate some network prefabs just after changing to a new scene the following way:
public override void OnNetworkSpawn()
{
if (!IsServer)
{
return;
}
var networkExitPrefab = Instantiate(myNetworkPrefab);
networkExitPrefab.localPosition = somePosition;
networkExitPrefab.eulerAngles = direction;
networkExitPrefab.GetComponent<NetworkObject>().Spawn(true);
}
Really simple code, which is on a network object that’s already on the new scene being loaded, that is, this code should execute just after the scene load is completed (at least in the host?). And ensures that the code is only executed on the host.
Before it was working just fine.
But now, with updated Netcode for GO 1.5.2, I’m getting the following error on clients, plus obviously the prefabs don’t seem to be insantiated;
[Netcode] Destroy a spawned NetworkObject on a non-host client is not valid. Call Destroy or Despawn on the server/host instead.
UnityEngine.Debug:LogError (object)
Unity.Netcode.NetworkLog:LogError (string) (at Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Logging/NetworkLog.cs:34)
Unity.Netcode.NetworkLog:LogServer (string,Unity.Netcode.NetworkLog/LogType) (at Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Logging/NetworkLog.cs:91)
Unity.Netcode.NetworkLog:LogErrorServer (string) (at Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Logging/NetworkLog.cs:52)
Unity.Netcode.NetworkObject:OnDestroy () (at Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkObject.cs:556)
I would guess it has to do with some race condition given that I’m trying to do this during scene change (using netcode scene manager), and it was just working by chance before and now it doesnt.
Other prefabs being instantiated later during gameplay seem to work fine thought, my network prefabs list on the network manager looks fine.