Search Unity

Reparent help

Discussion in 'Netcode for GameObjects' started by Nocheatin, Nov 15, 2021.

  1. Nocheatin

    Nocheatin

    Joined:
    Jan 22, 2016
    Posts:
    1
    Hello,
    I am currently migrating a project from MLAPI to Netcode. I was working through all the issues to make it work when I stumbled upon this Exception that I cannot figure out. It's telling me that a client is trying to reparent an object, but to my knowledge, I don't have any objects reparenting anything. I could really use some debugging suggestions for this topic.

    NotServerException: Only the server can reparent NetworkObjects
    UnityEngine.Debug:LogException(Exception)
    Unity.Netcode.NetworkObject:OnTransformParentChanged() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkObject.cs:658)
    UnityEngine.Transform:SetParent(Transform, Boolean)
    Unity.Netcode.NetworkSpawnManager:CreateLocalNetworkObject(Boolean, UInt32, UInt64, Nullable`1, Nullable`1, Nullable`1, Boolean) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Spawning/NetworkSpawnManager.cs:342)
    Unity.Netcode.NetworkObject:AddSceneObject(SceneObject&, FastBufferReader, NetworkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkObject.cs:1106)
    Unity.Netcode.CreateObjectMessage:Handle(UInt64, FastBufferReader, NetworkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Messaging/Messages/CreateObjectMessage.cs:26)
    Unity.Netcode.CreateObjectMessage:Receive(FastBufferReader, NetworkContext&) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Messaging/Messages/CreateObjectMessage.cs:21)
    Unity.Netcode.MessagingSystem:HandleMessage(MessageHeader&, FastBufferReader, UInt64, Single) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Messaging/MessagingSystem.cs:241)
    Unity.Netcode.MessagingSystem:processIncomingMessageQueue() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Messaging/MessagingSystem.cs:260)
    Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkManager.cs:1144)
    Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkManager.cs:1115)
    Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkUpdateLoop.cs:149)
    Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkUpdateLoop.cs:172)
     
  2. IJsLauw

    IJsLauw

    Joined:
    May 31, 2015
    Posts:
    11
    +1 same here, I reparent on the server. And that comes back as a command to reparent the local object to reflect the server changes (I would assume), so in my case it's the NetworkSpawnManager doing the reparenting on the client. Which should be ok, would it not?
     
  3. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    223
    Reparenting should work as long as you reparent the object just on the server and don't touch the hierarchy on the clients. Could you report a bug here?
     
  4. IJsLauw

    IJsLauw

    Joined:
    May 31, 2015
    Posts:
    11
    I think I solved it for my situation, I instantiated the prefab to a parent transform. So before I spawned it. When I removed that and set the parent after spawning it works fine.
     
unityunity