we say when a unit dies so we delist it but why we do that in OnStopServer() this method is for when server stops not when a unit dies
Hi there, as with any programming problem there are several approaches. In this case, when a unit is destroyed and it’s GameObject is destroyed on the server, then OnStopServer() will be called. Here we are taking advantage of this to use this existing callback to implement logic that has to do with the unit dying. This a robust solution, because it means no matter what happened to the unit, when it’s destroyed in the scene we will unsubscribe from it’s events and remove it from lists.
Another approach might be to trigger this in the health script or unit script, and have a UnitDeath() method. However, this means relying on that specific method for any time a unit dies, and if the code is changed that connection could be broken. I think there are multiple valid solutions to this problem, each with their own pros and cons.
Hi! I think the problem here is the name of the function and the fact there is another function with the same name doing different things.
The screenshot you posted is ftom NetworkManager callback, not NeworkBehaviour. The one used in the course is this one: https://mirror-networking.com/docs/api/Mirror.NetworkBehaviour.html#Mirror_NetworkBehaviour_OnStopServer
This is like the Stop() callback in Unity, but just called on the server.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.