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.13k stars 432 forks source link

Apparent state machine problem in NetworkManager #1595

Closed xaroth8088 closed 2 years ago

xaroth8088 commented 2 years ago

Describe the bug Essentially, calling Shutdown() while not in hosting or client mode triggers a state machine problem that prevents host mode from starting normally.

A sample project that exhibits this behavior can be found at https://github.com/xaroth8088/unity-networkmanager-bug

To Reproduce Steps to reproduce the behavior:

  1. Stop the project (if running)
  2. Run the project
  3. Click Shutdown
  4. Click Become Host

Actual outcome NetworkManager does not change to host mode. Also, the ConnectedClient game object does not get created.

Expected outcome NetworkManager changes to host mode. Also, a new ConnectedClient game object is inserted into the scene.

Screenshots N/A

Environment (please complete the following information):

Additional context Further unexpected behavior can be found by adding the following reproduction steps beyond the above set:

  1. Click Become Host

🙂 NetworkManager changes to host mode. Also, a new ConnectedClient game object is inserted into the scene.

  1. Click Shutdown
  2. Click Shutdown again
  3. Click Become Host

😢 NetworkManager does not change to host mode. Also, the ConnectedClient game object does not get created.

  1. Click Become Host again

🙂 NetworkManager changes to host mode. Also, a new ConnectedClient game object is inserted into the scene.

Additional additional context This was discovered while trying to enable players to arbitrarily switch between being a host and a client (and back). I know it ventures into feature request territory to mention this, but as an API consumer I feel that host/client-mode state management would be a lot simpler to manage if StartHost(), StartClient(), and Shutdown() were all smart enough to transition between states on their own, and were idempotent where applicable.

ashwinimurt commented 2 years ago

Tracked in our backlog MTT-3019

jeffreyrainy commented 2 years ago

Should be fixed in next release. Thanks for the report.