NetworkServer.Spawn() only on Server (with registered prefabs) [Unity 5.2.3f1]
I've been trying to figure this out for more than a month now, I cannot proceed in my game's development due to this error which appeared all of sudden. I have no idea what caused this but now NetworkServer.Spawn() only works on Server while the Client sends an error message (not always)
Spawn scene object not found for -int-
followed by
Did not find target for sync message for -int-
Class which takes care of registering prefabs:
public class RegisterPrefabs
{
public static void Register()
{
foreach (GameObject temp_ent in Resources.LoadAll<GameObject>(""))
{
if (temp_ent.GetComponent<NetworkIdentity>())
{
ClientScene.RegisterPrefab(temp_ent);
Debug.Log(temp_ent + " registered for loading!");
}
}
}
}
Registering prefabs:
public override void OnStartLocalPlayer()
{
RegisterPrefabs.Register();
}
Quick method for testing NetworkServer.Spawn():
public void TestSpawn(Vector2 pos, Quaternion rot)
{
Object[] randomWeapon = Resources.LoadAll("Guns/");
GameObject go = Instantiate(randomWeapon[Random.Range(0, randomWeapon.Length)], pos, rot) as GameObject;
NetworkServer.Spawn(go);
}
Any ideas? I desperately need help. I even tried changing connection's main channel (0) to ReliableSequenced (on Host code):
ConnectionConfig config = new ConnectionConfig();
config.AddChannel(QosType.ReliableSequenced);
config.AddChannel(QosType.Unreliable);
manager.StartHost(config, 8);
But no use. Instead, NetworkServer.Destroy() seems to be working just fine on Objects the scene comes with. Every GameObject has its own NetworkIdentity (and NetworkTransport), no Server Only, no Client Auth(although I tried with, no change)
Having similar issue with objects spawning on server but not client despite making sure everything is correct. Did you end up solving this?
Argh, I'm sorry buddy it's been so long I don't remember how I did it but here's a few things I can tell you to check:
Registering prefabs - try loading each folder ins$$anonymous$$d of everything in resources
using UnityEngine; using UnityEngine.Networking; using System.Collections; public class RegisterPrefabs { public static void RegisterAll() { foreach (GameObject temp_ent in Resources.LoadAll<GameObject>("Prefabs/")) { if (temp_ent.GetComponent<NetworkIdentity>()) { ClientScene.RegisterPrefab(temp_ent); } } } }
$$anonymous$$ake sure you only call the registering method when isLocalPlayer is true on a player
$$anonymous$$ake sure you're calling NetworkServer.Spawn() on Server with [Server] or [ServerCallback]
Your answer
Follow this Question
Related Questions
Networking concept and spawning questions 1 Answer
Cannot Spawn networkbehaviour gameobject 0 Answers
What does this error mean? 1 Answer
Not able to instantiate an object on the Client using [Command] UNET 0 Answers
Delay the spawning of networked player objects. Why is this so difficult with UNet..... 1 Answer