Add OnDespawnClient method to NetworkBehaviours #747
Replies: 3 comments
-
I can totally see the uses of this. Let me think of a good way to implement it. |
Beta Was this translation helpful? Give feedback.
-
I imagine using OnStopNetwork would work for if you wanted to use this for client or server, with the exception of clientHost. This would be really nice to have but it's not really possible without changing the override to the OnStop events, which means an API break, and we aren't quite ready to go there yet. It might be possible to squeeze in something on the NetworkObject that sets a field to true when the object is being destroyed. NetworkObject has first execution order so it should be safe to check something like, 'if (base.NetworkObject.IsDestroying) return` within the Stop callbacks. |
Beta Was this translation helpful? Give feedback.
-
Added nob.IsDestroying in 4.5.9 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
OnDespawnClient would be useful for playing death effects and animations on the client side, for example. The current alternative is to use OnStopClient, which is also fired when a scene gets unloaded, so that would mean playing all death effects even though it's useless and a waste of resources.
I read through the Despawn logic and it seems that whenever a scene gets unloaded you always call the Despawn method with DespawnType.Destroy. You could differentiate between automatic Destroy and "manual" destroy (which the user asked for explicitly) so that every Deinitialize call is either with a Despawn type (which I guess is always manual?) or with a Destroy type. If it is a manual Destroy, you call the OnDespawnClient, otherwise you don't (because that means that the scene got unloaded, for example).
Beta Was this translation helpful? Give feedback.
All reactions