Spawning dynamic object at runtime

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:

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

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?

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.