title: Unity Spawning child with client authority
body: <p>I'm currently learning how this whole networking thing works in unity. In my code I'm creating a spaceship made from multiple prefabs. </p>
  
  <p>It all starts with a single <code>Hardpoint</code>. A <code>Hardpoint</code> can hold a single object, which will be instantiated later on in the loop. </p>
  
  <p>In the <code>PlayerController</code> (the starting point) i have this code to spawn the first object, the cockpit:</p>
  
  <pre><code>[Command]
  void CmdOnConnect() {
      string json = GameObject.Find("TestPlayer").GetComponent&lt;ComponentObject&gt;().ToJSON();
      CompressedComponent compressedComponent = JsonUtility.FromJson&lt;CompressedComponent&gt;(json);
      gameObject.GetComponent&lt;Hardpoint&gt;().Hold(GameObject.Find("Component Repository").GetComponent&lt;ComponentRepository&gt;().cockpit[compressedComponent.componentNumber]);
      gameObject.GetComponent&lt;Hardpoint&gt;().SpawnComponent();
      gameObject.GetComponent&lt;Hardpoint&gt;().RollThroughDecompression(compressedComponent);
      Camera.main.GetComponent&lt;PlayerCamera&gt;().player = gameObject;
  }
  </code></pre>
  
  <p>Next up is the <code>SpawnComponent()</code> code, located in the <code>Hardpoint</code> script:</p>
  
  <pre><code>public void SpawnComponent() {
      Clear();
      CmdSpawn();
  }
  </code></pre>
  
  <p>CmdSpawn, also located in <code>Hardpoint</code>:</p>
  
  <pre><code>[Command]
  public void CmdSpawn()
  {
      Debug.Log("[COMMAND] Spawning " + holds.name);
      heldInstance = Instantiate(holds, transform.position, transform.rotation) as GameObject;
      heldInstance.transform.SetParent(transform);
      NetworkServer.SpawnWithClientAuthority(heldInstance, transform.root.gameObject);
  }
  </code></pre>
  
  <p>And finally <code>RollThroughDecompression</code>, which just calls the <code>Decompress()</code> function:</p>
  
  <pre><code>public void RollThroughDecompression(CompressedComponent c) {
      heldInstance.GetComponent&lt;ComponentObject&gt;().Decompress(c);
  }
  </code></pre>
  
  <p>And just to leave no information out, <code>Decompress()</code>:</p>
  
  <pre><code>public void Decompress(CompressedComponent c) {
      componentType = (Type)Enum.Parse(typeof(Type), c.componentType);
      componentNumber = c.componentNumber;
      UpdateHardPoints();
      GameObject[] typeRepository = GetRepository(componentType);
  
      //update children 
      int point = 0;
      foreach (Transform child in transform)
      {
          Hardpoint hardpoint = child.GetComponent&lt;Hardpoint&gt;();
          if (hardpoint != null) {
              if (c.hardpoints[point] != null) {
                  //get the hardpoint's repository
                  GameObject[] hardpointRepo = GetRepository((Type)Enum.Parse(typeof(Type), c.hardpoints[point].componentType));
                  //set the hardpoint to hold this object
                  hardpoint.Hold(hardpointRepo[c.hardpoints[point].componentNumber]);
                  hardpoint.SpawnComponent();
                  hardpoint.RollThroughDecompression(c.hardpoints[point]);
                  point++;
              }
          }
      }
  }
  </code></pre>
  
  <p>Sorry the code's a little messy/confusing but I've been driven up the walls trying to figure out why newly spawned objects don't have <code>client authority</code> with the exception of the first object spawned (likely because it's called from the <code>PlayerController</code>). I've been stuck on this problem for days now. Newly spawned objects are being set as children of the local player object and are even spawned with <code>NetworkServer.SpawnWithClientAuthority</code> yet when testing:</p>
  
  <p><code>Trying to send command for object without authority.</code> when calling <code>CmdSpawn()</code>.</p>
  
  <p><code>NetworkManager</code>:
  <a href="https://i.stack.imgur.com/5gKG7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5gKG7.png" alt="enter image description here"></a></p>
  
  <p>The result i'm getting:</p>
  
  <p><a href="https://i.stack.imgur.com/s0q3B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s0q3B.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the cockpit (very first part) gets spawned as expected. but parts mounted on those <code>Hardpoints</code> don't. To clarify, the <code>EmptyHardpoint</code> is just that. A hardpoint with no children, just an empty game object with the <code>hardpoint</code> script and <code>playercontroller</code> attached to it. The cockpit prefab also includes the <code>img</code> and <code>hardpoints</code></p>