Skip to content

ArgumentNullException in NetworkTransform when destroying a scene with disabled NetworkTransform GameObjects #2772

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

Closed
zachstronaut opened this issue Nov 20, 2023 · 1 comment · Fixed by #2807
Assignees
Labels
priority:high This issue has high priority and we are focusing to resolve it stat:imported Status - Issue is tracked internally at Unity type:bug Bug Report

Comments

@zachstronaut
Copy link

zachstronaut commented Nov 20, 2023

When developing in the Editor we might have a scene additively loaded, but testing the "real" game workflow might mean we immediately destroy that additive scene and load some other scene when we press the Play button in the Editor.

Netcode 1.6.0

If I do that and destroy an additive scene that had disabled GameObjects which had NetworkTransform components I get the following error:

ArgumentNullException: String reference not set to an instance of a String.
Parameter name: s
System.Text.Encoding.GetBytes (System.String s) (at <787acc3c9a4c471ba7d971300105af24>:0)
Unity.Netcode.CustomMessagingManager.UnregisterNamedMessageHandler (System.String name) (at ./Packages/[email protected]/Runtime/Messaging/CustomMessageManager.cs:218)
Unity.Netcode.Components.NetworkTransform.OnNetworkDespawn () (at ./Packages/[email protected]/Components/NetworkTransform.cs:2494)
Unity.Netcode.NetworkBehaviour.InternalOnNetworkDespawn () (at ./Packages/[email protected]/Runtime/Core/NetworkBehaviour.cs:528)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.NetworkBehaviour:InternalOnNetworkDespawn() (at ./Packages/[email protected]/Runtime/Core/NetworkBehaviour.cs:532)
Unity.Netcode.NetworkObject:InvokeBehaviourNetworkDespawn() (at ./Packages/[email protected]/Runtime/Core/NetworkObject.cs:1084)
Unity.Netcode.NetworkSpawnManager:OnDespawnObject(NetworkObject, Boolean) (at ./Packages/[email protected]/Runtime/Spawning/NetworkSpawnManager.cs:849)
Unity.Netcode.NetworkObject:OnDestroy() (at ./Packages/[email protected]/Runtime/Core/NetworkObject.cs:568)

There may be a bug here to address inside of UnregisterNamedMessageHandler and/or there may be adjustments you want to make to detect and not fire off OnNetworkDespawn in cases when OnNetworkSpawn has never fired.

For now, I just am checking for an empty m_MessageName:

/// <inheritdoc/>
        public override void OnNetworkDespawn()
        {
            if (!NetworkManager.ShutdownInProgress && NetworkManager.CustomMessagingManager != null && !string.IsNullOrEmpty(m_MessageName))
            {
                NetworkManager.CustomMessagingManager.UnregisterNamedMessageHandler(m_MessageName);
            }
            CanCommitToTransform = false;
            if (NetworkManager != null && NetworkManager.NetworkTickSystem != null)
            {
                NetworkManager.NetworkTickSystem.Tick -= NetworkTickSystem_Tick;
            }
        }
@zachstronaut zachstronaut added stat:awaiting-triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Nov 20, 2023
@NoelStephensUnity NoelStephensUnity self-assigned this Nov 21, 2023
@NoelStephensUnity
Copy link
Collaborator

Yeah, your work around is what should have been there. Nice catch and thank you for posting this issue!
👍

@NoelStephensUnity NoelStephensUnity added priority:high This issue has high priority and we are focusing to resolve it stat:import Status - Issue is going to be saved internally and removed stat:awaiting-triage Status - Awaiting triage from the Netcode team. labels Nov 21, 2023
@fluong6 fluong6 added stat:imported Status - Issue is tracked internally at Unity and removed stat:import Status - Issue is going to be saved internally labels Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:high This issue has high priority and we are focusing to resolve it stat:imported Status - Issue is tracked internally at Unity type:bug Bug Report
Projects
None yet
3 participants