Hi everyone,
In my game, the world is generated server-side, so in my world generation script I have some loops to instantiate prefabs.
The problem is, when I call NetworkServer.Spawn in these loops, it makes the client crash to desktop (even when the client is in the editor). Here is a simple implementation exemple (code is server side) :
void GeneratePlanets()
{
for (int i = 0; i < planetCount; i++)
{
Planet planet = Factory.CreatePlanet();
NetworkServer.Spawn(planet.gameObject);
}
}
Here is another implementation I’ve tested :
public class Factory : NetworkBehavior
{
List<GameObject> instanciatedObjects = new List<GameObject>();
void Update()
{
// Spawn every object instanciated by the server on the last frame
foreach (var item in instantiatedObjects)
NetworkServer.Spawn(item);
instanciatedObjects.Clear();
}
}
This is an exemple of implementation, I’ve tested many approaches but it fail everytime. Maybe I’ve missed something ?
Thanks in advance.