Search Unity

Re-Parenting under spawned NetworkObject's grandchild

Discussion in 'Netcode for GameObjects' started by Horst6667, Jun 24, 2022.

  1. Horst6667

    Horst6667

    Joined:
    Feb 5, 2018
    Posts:
    17
    Hi,

    Taking the reparenting example (https://docs-multiplayer.unity3d.co...ced-topics/networkobject-parenting/index.html), let's say I am spawning the Player (NetworkObject) at runtime, which has the several sub-NetworkObjects seen in the example.
    Next I spawn a Sword (NetworkObject) at runtime, parented under scene root.
    Now I want to reparent the Sword under RightHand (NetworkObject).
    This raises a SpawnStateException: "NetworkObject can only be reparented under another spawned NetworkObject".
    When taking a look at the Player Object in this state, one can see that the RightHand NetworkObject is indeed not yet spawned.

    In combination with the requirement that a NetworkObject can only be reparented directly under another NetworkObject, does that mean, that when I want to reparent a spawned Sword under the RightHand of the spawned Player, I will have to dynamically spawn a complete hierarchy of NetworkObjects down to RightHand (including all Hierachy-Nodes inbetween) before? (Including having to create separate network prefabs for every single hierarchy node...)

    This is not very practically. :-( I will try to workaround it and keep the Sword under scene root, moving it to the RightHand world position constantly under FixedUpdate.
     
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    The reparenting example is woefully out of date. Netcode no longer allows parenting as shown in the example (with a mix of NetworkObjects and non-NetworkObjects in the hierarchy), and since the latest version (pre10) also discourages nested non-scene NetworkObjects in general.

    See this post or this GitHub page for more details and workarounds. The GitHub page also indicates that this is unlikely to change in the future.
     
    brainwipe and Horst6667 like this.