Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Reparent help

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

  1. Nocheatin

    Nocheatin

    Joined:
    Jan 22, 2016
    Posts:
    4
    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:
    14
    +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:
    306
    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:
    14
    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.
     
  5. Delric

    Delric

    Joined:
    Nov 17, 2019
    Posts:
    1
    I encountered the same thing but my issue/solution was slightly different.

    If you instantiate a prefab with 2 params the second param is a Transform:
    Code (CSharp):
    1. Instantiate(prefab, transform);
    This will cause the above issue if you use the parent's transform.

    Instantiating with 3 param overload can take a position as second param instead:
    Code (CSharp):
    1. Instantiate(prefab, transform.position, Quaterinion.identity);
    This will not suffer from the same issue.
     
    CreativeChris likes this.
unityunity