# Spawning dynamic object at runtime

**URL:** https://discussions.unity.com/t/spawning-dynamic-object-at-runtime/599263
**Category:** Multiplayer & Networking
**Created:** [September 27, 2015, 10:25pm UTC](https://discussions.unity.com/t/spawning-dynamic-object-at-runtime/599263 "2015-09-27T22:25:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mmoe](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mmoe](https://discussions.unity.com/u/mmoe)
#### Post date: [September 27, 2015, 10:25pm UTC](https://discussions.unity.com/t/spawning-dynamic-object-at-runtime/599263/1 "2015-09-27T22:25:45Z")

</div>

What i want to do is create a gameobject dynamically on the server at runtime and use NetworkServer.SpawnWithClientAuthority() to spawn it on all clients and give authority to one client. In other words: spawn a object without a prefab and without pre-registering it.

What i’ve got so far:

```csharp
private NetworkHash128 customAssetId;

void Start() {
      
        customAssetId = NetworkHash128.Parse("e2656f");

        // ClientScene.RegisterSpawnHandler(customAssetId,SpawnHandler,UnSpawnHandler);
}

[Command]
public void CmdSpawndynamicobject(){
          GameObject dynamic = new GameObject();
          dynamic.AddComponent<NetworkIdentity>().localPlayerAuthority = true;
          dynamic.AddComponent<SomeComponent>().doSomething();
          GameObject subobject = new GameObject();
          subobject.transform.parent = dynamic.transform;

          NetworkServer.SpawnWithClientAuthority(eqWep,equippedAssetId, connectionToClient);
}

private static GameObject SpawnHandler(Vector3 position, NetworkHash128 assetID)
    {
        GameObject go = new GameObject();
        return go;
    }

    private static void UnSpawnHandler(GameObject gameObject)
    {
     
    }

    }

```

Trying do run CmdSpawndynamicobject() i get this error message on the clients:  
Client object spawned for 0000000000000e2656f does not have a network identity  
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

Everything works on the host though.

The docs are limited on this subject and i was hoping some of you could point me in the right direction.  
Thanks

---

<div class="post-metadata">

### Author: ![chrismarch\_1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/chrismarch_1/32/271269_2.png) [@chrismarch\_1](https://discussions.unity.com/u/chrismarch_1)
#### Post date: [September 29, 2015, 4:55pm UTC](https://discussions.unity.com/t/spawning-dynamic-object-at-runtime/599263/2 "2015-09-29T16:55:10Z")

</div>

Your client object, created in SpawnHandler, needs a NetworkIdentity, and probably the other components and field values you set in your command.

---

<div class="post-metadata">

### Author: ![mmoe](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mmoe](https://discussions.unity.com/u/mmoe)
#### Post date: [September 30, 2015, 1:49pm UTC](https://discussions.unity.com/t/spawning-dynamic-object-at-runtime/599263/3 "2015-09-30T13:49:22Z")

</div>

> [@chrismarch\_1](#):
>
> Your client object, created in SpawnHandler, needs a NetworkIdentity, and probably the other components and field values you set in your command.

Ah i get it, is there any way of passing additional parameters to the SpawnHandler function?

---

<div class="post-metadata">

### Author: ![chrismarch\_1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/chrismarch_1/32/271269_2.png) [@chrismarch\_1](https://discussions.unity.com/u/chrismarch_1)
#### Post date: [September 30, 2015, 5:29pm UTC](https://discussions.unity.com/t/spawning-dynamic-object-at-runtime/599263/4 "2015-09-30T17:29:24Z")

</div>

Not directly. You can use the network hash to lookup parameters stored on the client and associated with that hash. The parameters could be set before you build, or you could send them before spawning if they are not known until runtime.
