#OnStopNetwork not called on pooled objects when scene is changed on host

12 messages · Page 1 of 1 (latest)

stone chasm
#

Fishnet version : 4.6.5Pro

Hello ! So we stumbled upon a very specific bug : When changing scene, network objects present are destroyed by unity. When the pooled object are destroyed this way, on host, OnStopNetwork is not called. So from what I gathered :

  • First OnDisable is called, triggering a NetworkObject.Deinitialize with asServer as true. This triggers a StoreObject() in the pool, wich triggers a NetworkObject.ResetState() setting the NetworkObject.NetworkManager to null.
    The Deinitialize also calls InvokeStopCallbacks with asServer = true. This will call OnStopServer but not OnStopNetwork as the object is still initialized for the client (line 128), this is expected as the client part of the object is meant to be stopped on OnDestroy.

  • Then OnDestroyed is called but as NetworkObject.NetworkManager as set to null in the ResetState() previously, we skip all stop callback that should have been called for the client.

In particular this causes NetworkTransform to not unregister TimeManager_OnPostTick which spams null ref exceptions.

#

(also we're using yak, in case this may be the source of the project)

round timber
#

Looks like a bug to me, @tidal heath what do you think?

tidal heath
#

@stone chasm does just deleting any instantiated produce the same issue?

stone chasm
#

I just tried, and simply calling Destroy on the gameobject does not seem to reproduce the issue

tidal heath
#
public class MyTestScript : NetworkBehaviour //place on sceneObject.
{
    
    public override void OnStartNetwork() => Debug.Log($"OnStart called.");
    public override void OnStopNetwork() => Debug.Log($"OnStop called."); //If error occurs, this will not print.
}```

Setup:
* Add MyTestScript to a prefab.
* Start server in SceneA.
* Spawn prefab with MyTestScript.
* Connect clientHost.
* Load SceneB.

Reported outcome:
* SceneA is starting scene. 
* OnStart is called.
* Scene changes to SceneB without calling OnStop.
stone chasm
#

Yes, but you also need the network object MyTestScript is on to be pooled

stone chasm
#

No on a spawned object

#

You have SceneA, spawn in it a network object set to be pooled, with MyTestScript on it. Move to scene B, unloading scene A, without despawning the network object beforehand.
OnStopServer will be called, but not OnStopNetwork.

tidal heath
#

Updated my notes, sound right? @stone chasm