Hello,
I have looked around many places to try and find the answer to this problem, and it appears that no one else is seeming to have this particular trouble.
I am trying to spawn some objects on the server (which the clients should see just appear on their screen).
I know that I need NetworkServer.Spawn(GameObject go) to do this, and it works (meaning it spawns the object).
However, 1 frame later they are all gone and I have no idea why!
[Server]
void SpawnAll()
{
for (int i = 0; i < 10; i++)
{
Debug.Log("Spawning...");
GameObject obj = Instantiate(obstaclePrefab);
NetworkServer.Spawn(obj);
}
Destroy(this.gameObject);
}
When the level is loaded, that is called. It spawns the 10 objects, but then they are immediately destroyed or deleted or something happens to them. There are no errors that are occuring in the console, they just disappear.
If I run the server as a dedicated server the objects will persist (sort of_. Connecting a client to that LAN Server will then spawn errors (Failed to spawn server object).
I tried adding the prefab to the spawnable objects on the network manager, I tried registering the prefab via code, I tried loading the prefab in via code, the prefab DOES have a network identity (and a network transform). I tried turning on local player authority, server only, both, and none.
I’m using the default network manager (mostly) for now, with the default network manager HUD. When I click Start Host (H) if I quickly pause unity as fast as possible (ctrl+shift+p) I see this:
Yay cubes!
When I click the next frame button (Not unpause, just next frame) I see this (Good bye cubes T_T):
I have no inkling of why this is happening (note it happens with or without the Destroy(this.gameObject), or even if I just spawn 1 object instead of 10 in the loop).
Any help at all would be greatly appreciated!