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

Remote client can send RPC to NetworkObject that has been despawned on host, resulting in error #3007

Closed zachstronaut closed 2 months ago

zachstronaut commented 3 months ago

Remote client can send RPC to NetworkObject that has been despawned on host, resulting in error in ProxyMessage on the host when the RPC is received:

InvalidOperationException: An RPC called on a NetworkObject that is not in the spawned objects list. Please make sure the NetworkObject is spawned before calling RPCs.

Define your RPC like this and call it on the client:

[Rpc(SendTo.Everyone, RequireOwnership = false)]
void MyRpc() {}

Despawn the same NetworkObject on the host:

myNetObject.Despawn();

Depending on (I assume) message timing and latency, you can get your RPC message from the client to arrive on the host after the network object has despawned there, and then you get the error.

However, the remote client will not have called any OnNetworkDespawn methods yet so it has no way of knowing this will happen, and so I'm not sure how to prevent it?

Netcode 1.9.1

NoelStephensUnity commented 2 months ago

@zachstronaut This will be resolved in the next NGO v1.12.0 update. It will now only log a warning if developer logging is enabled and ignore the RPC. If developer logging is not set, then it just ignores the RPC.