MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.25k stars 775 forks source link

NetworkManager Callbacks #3912

Closed hyperbting closed 1 month ago

hyperbting commented 1 month ago

Describe the bug two things, one is the Callbacks order not as described in website observing OnServerAddPlayer triggered earlier than OnStartServer I just put Debug.Log on public override void OnStartServer() at any NetworkBehavior and OnServerDisconnectAction of a NewNetworkManagerWithActions created from scripttemplates

Debug-NetworkedManager-OnServerAddPlayer-before base.OnServerAddPlayer 11.12027
Debug-NetworkedPlayer-OnStartServer 11.12582
Debug-NetworkedManager-OnServerAddPlayer-after base.OnServerAddPlayer 11.12626

another thing is redoing the ResetPlayerNumbers() from Example/Basic with NewNetworkManagerWithActions, the result is different to example

[IMPORTANT] How can we reproduce the issue, step by step:

comparing to the example/basic BasicNetManager.cs https://github.com/MirrorNetworking/Mirror/blob/master/Assets/Mirror/Examples/Basic/Scripts/BasicNetManager.cs#L16 and https://github.com/MirrorNetworking/Mirror/blob/master/Assets/ScriptTemplates/51-Mirror__Network%20Manager%20With%20Actions-NewNetworkManagerWithActions.cs.txt#L217

the Invoke thing in BasicNetManager is after the base.OnServerAddPlayer(conn); if we move Player.ResetPlayerNumbers(); before base.OnServerAddPlayer(conn); the ResetPlayerNumbers() will find one less player

all Invoke() in NewNetworkManagerWithActions should after base.ooo(), maybe

Expected behavior using NewNetworkManagerWithActions should be the same to BasicNetManager /NetworkManager without Actions

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

MrGadget1024 commented 1 month ago

The scripts created by the templates are not intended to align with any particular example. They're just a convenient foundation for you to start from and you can mod them however you see fit to suit your game. In some cases, invoking the Action after the base method call may be appropriate, others it may not.