1
votes

I am using two different objects for player in network multiplayer game. Two different kinds of Gameobject will be instantiated by unity network Manager but the problem is there is only single property of playerprefab. How can i set two different objects even i tried to change it on run time but its giving me error.

Failed to spawn server object, assetId=4d293c8e162f3874b982baadd71153d2 netId=1 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

Failed to spawn server object, assetId=4d293c8e162f3874b982baadd71153d2 netId=7 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

1

1 Answers

1
votes

In the documentation of UNetManager:

if you want to customize the way player GameObjects are created, you can override that virtual function. This code shows an example of the default implementation:

public virtual void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
    var player = (GameObject)GameObject.Instantiate(playerPrefab, playerSpawnPos, Quaternion.identity);
    NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
}

You could change the prefab inside that code to the prefab you want to spawn.

Hope this helps you with your problem of choosing which prefab.