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.15k stars 435 forks source link

Add OnServerStopped event #2327

Closed RikuTheFuffs closed 1 year ago

RikuTheFuffs commented 1 year ago

Description

Hi, I noticed that in NetworkManager we have an event for when a client connects / disconnects, but for the server we only have the "started" one.

public event Action<ulong> OnClientConnectedCallback;
public event Action<ulong> OnClientDisconnectCallback;
public event Action OnServerStarted;

Solution I'd like

Would it make sense to add an OnServerStopped event, so that applications can do specific operations when a server instance is stopped but the application is still running?

public event Action OnServerStopped;

Additional context:

This could be useful to send analytics, do cleanups, etc...

NoelStephensUnity commented 1 year ago

As an additional thought, we might think about this:

RikuTheFuffs commented 1 year ago

I Opened a PR to add this event

ezoray commented 1 year ago

As an additional thought, we might think about this:

* OnClientStarted: Basically does the exact same thing as OnServerStarted but for Clients only

  * We could make a host invoke both

* OnShutdownComplete:  Both server and clients would invoke this once the NetworkManager is shutdown.

OnShutdownComplete would be very useful for what I'm doing as the client needs to disconnect from one server and join another but I'm not using Update at all currently so can't poll for it, instead I'm getting the server to disconnect them which isn't ideal for the workflow.

RikuTheFuffs commented 1 year ago

Update: This is now implemented in the develop branch! PR: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pull/2420

I also took the chance to add some more events in that PR, have a look at the changes in the changelog for all the details