Problem spawning prefabs client side, stand alone build.
Im trying to make it so that I can start any scene in my project, click a button and a NetworkManager is created and then you either join, or create a game as host. The code I have works perfectly when I run the game from the editor (I can start as both client and host).
The problem starts when I create a stand alone build, I can start as Host without any problems. But when I then try to join as a client I get "Failed to spawn server object, assetId=6c4737d3f84f22c44a4afb89d63ce6d2 netId=2", and nothing is spawned.
Here is the code that works for the Host,
var go = new GameObject("NetworkManager");
var netManager = go.AddComponent<NetworkManager>();
var resources = Resources.FindObjectsOfTypeAll<GameObject>();
foreach(var res in resources)
{
if(res.GetComponent<NetworkIdentity>() != null)
{
ClientScene.RegisterPrefab(res);
}
}
netManager.onlineScene = SceneManager.GetActiveScene().name;
var conn = netManager.StartHost();
And this is the code for the client:
var go = new GameObject("NetworkManager");
var netManager = go.AddComponent<NetworkManager>();
var resources = Resources.FindObjectsOfTypeAll<GameObject>();
foreach(var res in resources)
{
if(res.GetComponent<NetworkIdentity>() != null)
{
ClientScene.RegisterPrefab(res);
}
}
netManager.onlineScene = SceneManager.GetActiveScene().name;
if(string.IsNullOrEmpty(ip))
{
ip = "127.0.0.1";
}
netManager.networkAddress = ip;
netManager.StartClient();
The code is pretty much the same between the two, the only real diffrence is that we use StartHost as the host and StartClient as client. Im at a complete loss about this...
They only thing I can think would be diffrent is maybe assetID or the netID? But one would think unity would have the same netID & assetID on the same resources Im running the same executable after all..
Your answer
Follow this Question
Related Questions
Client choice of prefabs on a NetworkLobbyManager 0 Answers
What does this error mean? 1 Answer
NetworkServer.Spawn() only on Server (with registered prefabs) [Unity 5.2.3f1] 0 Answers
since update to 5.5.1f1 i keep getting Network is not active Error 0 Answers
Unet Spawn Prefabs When Scenes Changes 0 Answers