Hi!
I’m trying to create a multiplayer game in Unity. I want to spawn a few cubes when the server starts, but nor Network.Instantiate nor NetworkServer.Spawn is working.
When I try to call Network.Instantiate() the error is “Failed Network.Instantiate because we are not connected.”
When I use NetworkServer.Spawn(), the objects do get spawned, but they all have the same network viewID (0). If I try to allocate the viewId manually, I get the error that I should increase the minimum client networkViewId count. I don’t have any other objects in the scene, and also I tried setting it to 500, but the error remains.
The script runs Server Only.
The script itself:
int itemsToSpawn = 6;
List<GameObject> itemPrefabs = new List<GameObject>();
void Start()
{
for ( int i = 0; i < itemsToSpawn; i++)
{
Network.Instantiate(itemPrefabs[random], position, location, 1);
}
}
I also tried OnStartServer() instead of Start(), did not change anything.
itemPrefabs is a List of prefabs assigned throug the inspector, currently there is only a cube in it.
Also instead of Network.Instantiate, I tried using NetworkServer.Spawn(), like this:
int itemsToSpawn = 6;
List<GameObject> itemPrefabs = new List<GameObject>();
void Start()
{
for ( int i = 0; i < itemsToSpawn; i++)
{
GameObject item = (GameObject)Instantiate(itemPrefabs[random], position, location);
NetworkServer.Spawn(item);
}
}
Thanks for the help.