Reparent help

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, Nullable1, Nullable1, 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:b__0_0() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkUpdateLoop.cs:172)

+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?

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?

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.

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:

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:

Instantiate(prefab, transform.position, Quaterinion.identity);

This will not suffer from the same issue.

2 Likes