New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destroy a spawned NetworkObject on a non-host client is not valid error if a server spawns NetworkObjects while a client connects to the already running game #2706
Comments
|
There is something you could do on your end to resolve the issue(s) you are experiencing:
I went ahead and attached an updated version of your netcode test project (thank you for this repro project! It greatly helps in many ways) The Let us know if that resolves your issue or if you run into any other issues using those adjusted NetworkSceneManager settings? We will look into either improving the error message or the possibility of deferring the processing of CreateObjectMessages until after client synchronization has completed (or possibly both). |
|
I encountered the same behaviour with our project. This project is using OpenXR and the XR Interaction Toolkit as well. On connect the client spawns via ServerRpc its own XR rig with client ownership. We encountered this bug when the users are connecting simultaneously, so that the XR rig of other clients is spawned in the unloading scene - we worked around this like @NoelStephensUnity proposed by using additive client synchronization and post synchronization scene loading. But we still encounter this bug by changing scenes on the server when the server spawns multiple objects (5 objects of the same prefab are spawned correctly, the other 3 to 8 objects of another prefab are spawned and run into this issue) by a NetworkBehaviour's OnNetworkSpawn. Our current workaround is letting the server spawn those network objects after the callback of the LoadEventCompleted scene event. Since this is pretty ugly (some clients can see the scene before the objects are spawned), I don't think that this is the intended behaviour. I also tried using the fix from your pull request on version 1.6.0 of Netcode, since a checkout of the develop branch makes Unity 2021.3.22f1 continuously throw errors when loaded into the package manager. Using this fix with 1.6.0 makes Unity check whether a Synchronize event is active via IsSceneEventActive, but the SceneEventDataStore on the client is always empty, so it returns false and doesn't defer the objects. I'm not sure why this is the case - we are using the internal SceneManagement of Netcode. I don't want to rule out that I am using that in a wrong way, but everything else seems to be working as intended. Since the deadline of the project is coming up pretty soon, we'll have to use the workaround - I just wanted to let you know that there seem to be cases when this bug still occurs. If you need a sample project for this, let me know - but I'll probably won't be able to provide you with this in the next few days because of the project's deadline, that inches closer every minute. |
|
@lumium-mpaff
However, I will definitely look into deferring CreateObjectMessages for SceneEventType.Load before that PR is finalized. |
If you have time (understanding your deadline), could you provide the errors you are encountering in the editor when using the develop branch? Not sure if this is how you did it, but you can use a specific branch by replacing your packages/manifest.json file's com.unity.netcode.gameobjects entry to something like this: Where everything after the # is nothing more than the branch name. You might see if that works out better for you. |
|
@lumium-mpaff 👍 |
Description
If a server spawns NetworkObjects while a client connects to the already running game, I get this error:
Client error:
[Netcode] Destroy a spawned NetworkObject on a non-host client is not valid. Call Destroy or Despawn on the server/host instead.
...
(at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkObject.cs:556)
Server error:
[Netcode-Server Sender=1] Destroy a spawned NetworkObject on a non-host client is not valid. Call Destroy or Despawn on the server/host instead.
Sample project:
https://www.dropbox.com/scl/fi/sw7xgbyhxrz1vcchojnkc/NetcodeTest.zip?rlkey=jhkbq0w9k803p3al5ife9iz7p&dl=0
In the game project we do not spawn a lot of network objects, so the error is really rare. But in the test project it is to detect the problem.
Unity forum thread:
https://forum.unity.com/threads/destroy-a-spawned-networkobject-on-a-non-host-client-is-not-valid.1493204/
Reproduce Steps
Environment
The text was updated successfully, but these errors were encountered: