Mirror
Mirror copied to clipboard
Added NetworkBehaviour OnEnableClient() & OnDisableClient()
This PR adds an simple OnEnableClient() and an OnDisableClient() method for the NetworkBehaviour. Will be called if the NetworkBehaviour gets "visible" or "hidden" on the client or host.
If an InterestManagement is used, this callbacks will also be called if the NetworkBehaviour gets visible or hidden on the client/host.
OnDisableClient() will also be called when the object gets destroyed on the server and is visible to an client or the host
A little bit late but also added OnEnableServer() & OnDisableServer() if someone is interested in it.
OnEnableServer() Like OnEnable(), called on server and host - will be called if the object becomes visible to atleast 1 client and was hidden (Disabled) before
OnDisableServer() Like OnDisable(), called on server and host - will be called if the object gets hidden and no one can see it anymore or if the object gets destroyed and the object is visible to atleast 1 client
This is actually very helpful to understand if it's possible to send NetworkServer.send and if the client will be able to register it in time
I don't really see the value in this over OnStartClient / OnStopClient overrides where you can set your own flags to suit your purposes.
@MrGadget1024
Main purpose was to use this in some scenarios where the server is also an player (host). OnStartClient / OnStopClient is only called once for the host.
Example: Lets say you want to call something for the Player when the NetworkBehaviour gets visible to the player.
And OnEnableServer/OnDisableServer just some extra features that gets called when Object is completly hidden to all players or when it becomes visible to atleast 1 player.
Example: You only want to do something with the Object on the Server when its visible to atleast 1 player.
All these things can solved in other ways.. correct, this are only functions/callbacks that can easier be used. Saved me a lot of time in some projects.
closing because 2 years old and see mrg's comment above