Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved NullReferenceException: Object reference not set to in Unity.Netcode.NetworkTransform

Discussion in 'Netcode for GameObjects' started by firebird721, Aug 2, 2023.

  1. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    Title: NullReferenceException: Object reference not set to an instance of an object in Unity.Netcode.NetworkTransform

    Body: Hello Unity community,

    I'm encountering an issue with my Unity project that involves the Unity.Netcode.NetworkTransform component. My game loads the lobby, relay, and player selection without any problems. However, when the game starts, the player isn't spawned, and I receive the following error:

    kotlin
    NullReferenceException: Object reference not set to an instance of an object
    Unity.Netcode.Components.NetworkTransform.OnNetworkObjectParentChanged (Unity.Netcode.NetworkObject parentNetworkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Components/NetworkTransform.cs:2529)
    Unity.Netcode.NetworkObject.InvokeBehaviourOnNetworkObjectParentChanged (Unity.Netcode.NetworkObject parentNetworkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkObject.cs:691)
    Unity.Netcode.NetworkObject.ApplyNetworkParenting (System.Boolean removeParent, System.Boolean ignoreNotSpawned) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkObject.cs:1015)
    Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocallyCommon (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Spawning/NetworkSpawnManager.cs:596)
    Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocally (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Spawning/NetworkSpawnManager.cs:502)
    Unity.Netcode.NetworkSceneManager.OnServerLoadedScene (System.UInt32 sceneEventId, UnityEngine.SceneManagement.Scene scene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/SceneManagement/NetworkSceneManager.cs:1630)
    Unity.Netcode.NetworkSceneManager.OnSceneLoaded (System.UInt32 sceneEventId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/SceneManagement/NetworkSceneManager.cs:1600)
    Unity.Netcode.SceneEventProgress.<SetAsyncOperation>b__37_0 (UnityEngine.AsyncOperation asyncOp2) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/SceneManagement/SceneEventProgress.cs:262)
    UnityEngine.AsyncOperation.InvokeCompletionEvent () (at <3e2118a0a67041869c87922a11f4a02f>:0)

    I'm using Unity version 2023.1.6 and Unity.Netcode version 1.5.2. I haven't made any recent changes that I'm aware of, and this problem seemed to occur suddenly.

    Could someone please help me understand what might be causing this issue and how I can resolve it? I'd greatly appreciate any insights or suggestions to troubleshoot and fix this problem.

    Thank you in advance for your assistance.
     
  2. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    day after the game still being imparied because this error- ithink the main damage is that the player is not spaend after the rely and lobby. (it worked for a long time and suddeny it stoped)
     
  3. ALherbier

    ALherbier

    Joined:
    Sep 1, 2020
    Posts:
    8
    Same for me. It used to work and today it does not anymore. I have recently made an update and the NetworkManager Component ask to make a small change on network prefabs which became a list that as to be set somewhere in the project (maybe this is related to this). I've noticed also that an upgrade of netcodeforgameobject was available maybe one needs to upgrade this package ??
     
  4. ALherbier

    ALherbier

    Joined:
    Sep 1, 2020
    Posts:
    8
    It is strange because the error
    (for me it is
    NullReferenceException: Object reference not set to an instance of an object
    Unity.Netcode.Components.NetworkTransform.OnNetworkObjectParentChanged (Unity.Netcode.NetworkObject parentNetworkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Components/NetworkTransform.cs:2516)
    ), points towards this line in the NetworkTransform.cs script : m_ScaleInterpolator.Clear();
    I am using the script ClientNetworkTransform for syncing the transform in my network prefab
     
    HirokiYamada likes this.
  5. HolyMacarony

    HolyMacarony

    Joined:
    Feb 22, 2021
    Posts:
    1
    Hello! has anyone figured out what the problem is by now? i have the exact same problem following codemonkey tutorial at this point:
    I cannot find the solution to this. Any hints would be greatly appreciated:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Unity.Netcode.Components.NetworkTransform.OnNetworkObjectParentChanged (Unity.Netcode.NetworkObject parentNetworkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Components/NetworkTransform.cs:2624)
    3. Unity.Netcode.NetworkObject.InvokeBehaviourOnNetworkObjectParentChanged (Unity.Netcode.NetworkObject parentNetworkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkObject.cs:691)
    4. Unity.Netcode.NetworkObject.ApplyNetworkParenting (System.Boolean removeParent, System.Boolean ignoreNotSpawned) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkObject.cs:1015)
    5. Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocallyCommon (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Spawning/NetworkSpawnManager.cs:596)
    6. Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocally (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Spawning/NetworkSpawnManager.cs:502)
    7. Unity.Netcode.NetworkSceneManager.OnServerLoadedScene (System.UInt32 sceneEventId, UnityEngine.SceneManagement.Scene scene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/SceneManagement/NetworkSceneManager.cs:1630)
    8. Unity.Netcode.NetworkSceneManager.OnSceneLoaded (System.UInt32 sceneEventId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/SceneManagement/NetworkSceneManager.cs:1600)
    9. Unity.Netcode.SceneEventProgress.<SetAsyncOperation>b__37_0 (UnityEngine.AsyncOperation asyncOp2) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/SceneManagement/SceneEventProgress.cs:262)
    10. UnityEngine.AsyncOperation.InvokeCompletionEvent () (at <cd14705e8f094afcb566740ab5e8c02d>:0)
    11.  
    Thank you very much!
     
  6. PlayboyMinimi

    PlayboyMinimi

    Joined:
    Jul 15, 2018
    Posts:
    2
    I have this problem here, and i also dont know how i can fix this problem:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Unity.Netcode.Components.NetworkTransform.OnNetworkObjectParentChanged (Unity.Netcode.NetworkObject parentNetworkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Components/NetworkTransform.cs:2529)
    3. Unity.Netcode.NetworkObject.InvokeBehaviourOnNetworkObjectParentChanged (Unity.Netcode.NetworkObject parentNetworkObject) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkObject.cs:691)
    4. Unity.Netcode.NetworkObject.ApplyNetworkParenting (System.Boolean removeParent, System.Boolean ignoreNotSpawned) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkObject.cs:1015)
    5. Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocallyCommon (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Spawning/NetworkSpawnManager.cs:596)
    6. Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocally (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Spawning/NetworkSpawnManager.cs:502)
    7. Unity.Netcode.NetworkConnectionManager.HandleConnectionApproval (System.UInt64 ownerClientId, Unity.Netcode.NetworkManager+ConnectionApprovalResponse response) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Connection/NetworkConnectionManager.cs:609)
    8. Unity.Netcode.NetworkManager.HostServerInitialize () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkManager.cs:892)
    9. Unity.Netcode.NetworkManager.StartHost () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkManager.cs:848)
    10. UnityEngine.Debug:LogException(Exception)
    11. Unity.Netcode.NetworkManager:StartHost() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Runtime/Core/NetworkManager.cs:853)
    12. Unity.Netcode.Editor.NetworkManagerEditor:OnInspectorGUI() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.2/Editor/NetworkManagerEditor.cs:292)
    13. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
     
  7. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    437
    firebird721 likes this.
  8. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    its great!!!! i updgrad to 1.71 and everthing dandy! thx unity
     
    RikuTheFuffs-U likes this.
  9. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Running into this problem in 1.71.
    m_ScaleInterpolator.Clear();
    is throwing NREs... can't seem to get it to debug any further information...

    I was trying to allow the player prefab to switch between VR and pancake setups, so there were disabled NetworkTransforms within the player prefab. Moving them out to separate VRPlayer and PancakePlayer prefabs with some spawn logic and having all NetworkTransforms enabled on spawn seems to have fixed it.
     
    Last edited: Jan 22, 2024