Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.1k stars 430 forks source link

Improved Logging for Deferred Message Cleanup #2963

Open Reag opened 3 days ago

Reag commented 3 days ago

Is your feature request related to a problem? Please describe. For a while now, we've been receiving the following warning when despawning objects: [Netcode] Deferred messages were received for a trigger of type OnSpawn with key 21, but that trigger was not received within within 1 second(s). All network objects in our scene are pooled to save resources, and we have a multitude of network behaviors controlling the various objects. The warning itself is a bit difficult to understand, but I believe it is trying to communicate that some network message was send (say, change transform parent, network variable update, ownership change, etc) but the object was already despawned on the server. As such, NGO assumes that this is a message for an object that will be spawned and queues them up as deferred messages to be preformed when the object is spawned. Because these objects are pooled, if there is low activity in the pool, these messages time out with this warning. In addition, we believe a glitch we have is caused by these deferred messages being invoked if the object is respawned before the 1 second timeout.

The issue here is most certainly our fault. Somewhere in our code, something is attempting to perform network actions on a despawned, or soon to be despawned, object. However, we have no way of figuring out what is causing this.

Describe the solution you'd like Ideally, we would like to have some sort of 'network stack trace' that would tell us who, what, and where this deferred message came from. For example, an error message like [Netcode] Deferred message from 'OnGrabEnd_ServerRpc' were received from ClientId 1 for a trigger of type OnSpawn on NetworkObjectId 21, but that trigger was not received within within 1 second(s). Check to see if <Some advice for avoiding this issue> would be ideal. As it stands right now, I have no way of isolating who is sending messages to this despawned object, or what these messages contain. I know that some behavior or client performed an action it shouldn't, but not what the action was.

Describe alternatives you've considered I've attempted to attach a debugger to the DeferredMessageManager to see whats causing these issues, but my own knowledge of how the internals of NGO function is not sufficient for me to draw meaningful information about whats happening. I'm fairly certain at least some of the information that would be helpful to me is here, but lack the knowledge to make it useful.

Additional context Our network scene is very complex, with a significant amount of moving parts. Most things are pooled to save resources, which is what I believe is causing this issue. If the objects where just destroyed, these lingering messages would just be discarded. I suspect that this pooling is leading to another bug we have when a particular object of ours is destroyed in a specific way.