OnStartServer spawned assignment moved to NetworkServer caller

This commit is contained in:
vis2k 2022-11-10 20:17:25 +01:00
parent c6df8f01d8
commit 75e7af1312
2 changed files with 3 additions and 4 deletions

View File

@ -639,10 +639,6 @@ internal void OnStartServer()
//Debug.Log($"OnStartServer {this} NetId:{netId} SceneId:{sceneId:X}");
// add to spawned (note: the original EnableIsServer isn't needed
// because we already set m_isServer=true above)
NetworkServer.spawned[netId] = this;
// in host mode we set isClient true before calling OnStartServer,
// otherwise isClient is false in OnStartServer.
if (NetworkClient.active)

View File

@ -1191,6 +1191,9 @@ static void SpawnObject(GameObject obj, NetworkConnection ownerConnection)
identity.isLocalPlayer = NetworkClient.localPlayer == identity;
identity.netId = NetworkIdentity.GetNextNetworkId();
// add to spawned (after assigning netId)
spawned[identity.netId] = identity;
// callback after all fields were set
identity.OnStartServer();
}