Skip to content

OnNetworkDespawn is not called on server side when a client disconnects #2315

@tynitoon

Description

@tynitoon

Description

The function OnNetworkDespawn() on server side is not called when a client leave the game or call the NetworkManager.Singleton.Shutdown() function.

Normaly, OnNetworkDespawn() should be call on server and client :
https://docs-multiplayer.unity3d.com/netcode/current/api/Unity.Netcode.NetworkBehaviour/index.html
In the version 0.1.0 this bug wasn't existing.

Reproduce Steps

  1. Create a new project (the bug has been tested on 2021.3.13.f1 and 2021.2.8f1)
  2. Create a new gameobject "Network" and add a NetworkManager component and a Unity Transport Component (the bug has also been tested with UNet transport)
  3. Create a script "BuggyPlayer" that inherit from NetworkBehaviour and write the function "public override void OnNetworkDespawn()", add a Debug.Log("Despawn"); in it
  4. Create a Prefab "Player", and add Network Object Component and your BuggyPlayer component
  5. Drag and drop your prefab in the NetworkManager component in the inspector
  6. Create a script "DummyHUD" then create 3 functions "void HostServer()", "void JoinServer()", "void ShutdownNetwork()", and call in HostServer function "NetworkManager.Singleton.StartHost();" in JoinServer "NetworkManager.Singleton.StartClient();" and in ShutdownNetwork "NetworkManager.Singleton.Shutdown();".
  7. Add your DummyHUD component to the gameobject "Network"
  8. create 3 buttons and link them to each of the functions from DummyHUD
  9. Make a build
  10. Start server on the editor then click your button linked to the HostServer function
  11. Launch a client (which you have just built) and click on your button linked to the JoinServer function
  12. Check that the scene has 2 Player(clone) in the hierarchy (that means that the client is correctly connected)
  13. Click on the client the button linked to "ShutdownNetwork" or close the client (both give the same result)

Actual Outcome

You will see that there is no output "Despawn" in the console of the server side.

Expected Outcome

The output "Despawn" should be visible in the consol on the server side (by the way it is visible on client side)

Environment

  • OS: Windows 11
  • Unity Version: 2021.3.13.f1 and 2021.2.8f1
  • Netcode Version: 1.1.0

Metadata

Metadata

Labels

priority:mediumThis issue has medium priority and may take some time to be resolvedstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions