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