-
Notifications
You must be signed in to change notification settings - Fork 464
Closed
Labels
priority:highThis issue has high priority and we are focusing to resolve itThis issue has high priority and we are focusing to resolve itstat:importStatus - Issue is going to be saved internallyStatus - Issue is going to be saved internallytype:bugBug ReportBug Report
Description
Description
NGO v1.12.0 & v1.11.0 does not trigger OnNetworkDespawn function on NetworkObjects associated with Disconnecting Clients on the Server side when INetworkPrefabInstanceHandler is used.
Reproduce Steps
- Use SpawnAsPlayerObject with INetworkPrefabInstanceHandler
- Disconnect a Client from the Hosting Server
- Monitor the OnNetworkDespawn function on the Player script. It does not execute on the Server when the Client disconnects.
Upgrade to NGO v2.1.1
- Repeat the above steps.
- Monitor the OnNetworkDespawn function which triggers on the Server now for the player objects associated with the disconnecting client.
It doesn't seem like I'm the only one experiencing this issue (Additionally the Destroy function in INetworkPrefabInstanceHandler is being called twice per NetworkObject, refer to the thread for more details):
https://discussions.unity.com/t/onnetworkdespawn-ondestroy-from-networkbehaviour-does-not-get-executed-on-the-hosting-client-when-using-inetworkprefabinstancehandler/1578473/6
Expected Outcome
OnNetworkDespawn should execute on the Server for NetworkObjects associated with the Disconnecting Clients.
My code:
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public class NetcodeSpawnableHandler : INetworkPrefabInstanceHandler
{
private readonly SpawnableData spawnableData;
public NetcodeSpawnableHandler(SpawnableData spawnableData)
{
this.spawnableData = spawnableData;
}
public void Destroy(NetworkObject networkObject)
{
var spawnable = networkObject.GetComponent<Spawnable>();
if (spawnable != null)
{
networkObject.gameObject.SetActive(false);
}
else
{
Debug.LogWarning("Attempted to despawn an object not managed by SpawnableData.");
}
}
public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation)
{
Debug.Log("NetcodeSpawnableHandler: " + spawnableData.name);
var spawnable = spawnableData.Spawn(null, position, rotation);
return spawnable.GetComponent<NetworkObject>();
}
} public static async Task RegisterSpawnableToNetworkManager(SpawnableData spawnableData)
{
await spawnableData.PreloadAssetReference();
// Add the custom handler for the specified prefab
NetworkManager.Singleton.PrefabHandler.AddHandler(
spawnableData.assetReferenceHandle.Result,
new NetcodeSpawnableHandler(spawnableData)
);
}Screenshots
Environment
- OS: Windows 11
- Unity Version: 2023
- Netcode Version: 1.11.0 and 1.12.0
ezoray
Metadata
Metadata
Assignees
Labels
priority:highThis issue has high priority and we are focusing to resolve itThis issue has high priority and we are focusing to resolve itstat:importStatus - Issue is going to be saved internallyStatus - Issue is going to be saved internallytype:bugBug ReportBug Report