- Home /
UNet NetworkServer.Spawn() not working / Failed to spawn server object, assetId=
Well, after some long hours I'm back here again with this creepy error.
As the title states - my "Network" is not working well. I have done everything obvious and I'm still getting this dirty error:
"Failed to spawn server object, assetId=48410ff8cf25a3646ba9e31b8553afcb netId=5"
I honestly recheck everything nearly 150 times and it is all good. NetworkManager has the Player prefab set, the "non-working" prefab is set in the NetworkManager Spawn Info unfold "Registered Spawnable Prefabs" This last one is also correctly set in the PrefabSpawner. Everything is just as it is indicated in here
All objects have correctly set up the NetworkIdentity - the PrefabSpawner has it set to "Server Only". All objects have NetworkTransform set also.
Everything is just set up fine but, still on the client node I receive this error once and over again.
It only happens on the client node, not on the host.
I'v already read like 4 dozens of topics, questions and answers, most of them having absolutely the same problem, some of them have solution - but unfortunately nothing worked for me : (
Also followed the Unity tutorials step by step. No way!!
Please help.
Spawner script:
using UnityEngine;
using UnityEngine.Networking;
public class PlatformSpawner : NetworkBehaviour
{
public GameObject platformPref;
public int numberOfPlatforms;
public override void OnStartServer()
{
for (int i = 0; i < numberOfPlatforms; i++)
{
var spawnPosition = new Vector3(
0.0f,
i * 2,
0.0f);
var spawnRotation = Quaternion.Euler(
0.0f,
0.0f,
0.0f);
var platform = (GameObject)Instantiate(platformPref, spawnPosition, spawnRotation);
NetworkServer.Spawn(platform);
}
}
}
Answer by Datapax · Jan 06, 2017 at 11:42 PM
As I already saw in all cases, including this one, the problem can be due to many different causes.
In this case:::
I ended up switching the network manager Log Level to "Developer" and ran through all the logs there one by one. There I spotted a log, not an "error" nor a "warning" - just a simple log:
Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used. UnityEngine.Networking.NetworkManager:Awake()
Well, that was something! I had to pull my hairs off to find this "multiple" NetworkManager in my project. And just because it is NOT called a "NetworkManager" but a "LobbyManager" - however, this was the "nasty" problem causer.
I looked it all over, and of course, there it was, another "Registered Spawnable Prefabs" field, which logically was completely "empty".
Finally, just dragging up my prefab into the field was the solution to my headache.
So, if you are using the Unity Network Lobby and your project is using a separate UNet NetworkManager, AND you are having this same issue, make sure you register your prefabs on both "NetworkManagers".
I hope this helps others : ) Good luck and happy developing!
Unity 5.4.2f2
thanks a lot for this but unfortunately I don't think this helps me. I have this problem: I made a different project for the client and a different one for the server, but when I connect as a client to the server, the Player Prefab GameObject from the Network$$anonymous$$anagerScript spawns on the server but it doesn't spawn on the client, it throws an error: "Failed to spawn server object, did you forget to add it to the Network$$anonymous$$anager? assetId=ca70e3141cc66db4c9d0bcf4b42a7854 netId=1" but I have the PlayerPrefab assigned in Network$$anonymous$$anager on both the server project, and the client project Thanks a lot for any response!!!
Answer by TwinCrows · Dec 10, 2020 at 01:05 AM
For me, the problem was happening because the prefabs were being registered after the client attempted to load them. I was registering them, but just not early enough...
So I moved my ClientScene.RegisterPrefab(x) statements to an Awake() trigger and they spawned again perfectly :)
Like Datapax above suggested, changing the log level to Developer helped! You'll be able to see the exact order of events with the Network Manager.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Qos type ReliableFragmented channel, won't fragment our stream 2 Answers
are client hosted servers limited by my 20 person ccu? 0 Answers
Creating non-player gameobject with Client authority 0 Answers
How can I transfer hosts once the current host leaves? 0 Answers