Failed to spawn server object, assetid=...
I can't find an answer that works for me for this error. I've spent days and just can't figure it out. I'm trying to make a multiplayer project, and it works to an extent, but when i spawn an object with NetworkServer.Spawn() or .SpawnWithClientAuthority(), i get an error saying "Failed to spawn server object, assetId= netId=2"
None of the answers i've found for other people seem to solve the problem. Here's the code i know is relevant:
Class 1:
public class GUIControl : MonoBehaviour {
public virtual void SetupScene ()
{
if (canSpawnPlayer == true)
{
manager.SpawnPlayer(loadout);
}
}
}
Class 2, on my network manager:
public class MyManager : NetworkManager {
public void SpawnPlayer (Weapons.Loadout lo) {
MyControl.SpawnPlayer(lo);
}
}
Class 3, the object spawned automatically by the network manager upon joining,
public class MyControl : NetworkBehaviour {
public GameObject playerPrefab;
void Start () {
ClientScene.RegisterPrefab (playerPrefab);
}
public void SpawnPlayer (Weapons.Loadout lo) {
GameObject obj = Instantiate (playerPrefab, Vector3.zero, Quaternion.identity);
obj.GetComponent<Player>().loadout = lo;
NetworkServer.SpawnWithClientAuthority (obj, connectionToClient)
}
}
If anyone knows possible causes for this error, please let me know.
Answer by Bratenhans · Mar 01, 2017 at 07:35 PM
Maybe it's a timing problem. Do you call the SpawnPlayer-Method before or after the Start-Method? To avoid such timing issues, I normally register common prefabs in the OnClientConnect-Function (i.e. the player prefabs).
Your answer
Follow this Question
Related Questions
Looking for a Simple MultiPlayer Server 0 Answers
Unity Photon Handle Match Data 0 Answers
Unity [PUN] New Instantiated players cannot see previously instantiated players 0 Answers
multiplayer game -how to connect each game-object to specific network player 0 Answers
Is there any benefit to calling NetworkTransport.Receive multiple times per tick? 0 Answers