UNET Player Object Creation Error: Failed to spawn server object

I am attempting to create a player object for a connecting client. I have set the PlayerPrefab variable to be an empty object with a NetworkIdentity attached to it. The issue is that once the client connects, the player object is created on the server but the client gets this error:

Failed to spawn server object
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate(). 

I am not sure if there is something that I have set up incorrectly on the server or client in order to get this error. The client does connect to the server and switch scenes successfully just before this happens.

1 Answer

1

So for anyone else dealing with this problem, I found my solution. I have my client and server code in two separate projects which was an issue because the player prefabs for the client and server must share the same meta file in order to work. This could also be the case for any networked object someone might want to create through NetworkServer.Spawn() but I have not tested it personally. Good luck to anyone dealing with a similar issue.

CommandoJones, could you please share the demo project? I have issues with spawning..

Hey iyakov, unfortunately I don't have a small demo project to share. I found this issue while working on a rather large code base. However I can say that my particular issue with spawning a player object happened because I have two separate projects. One for the server and one for the client. So when I assigned my player objects, the prefabs I was using did not share the same meta data which caused issues. If you are having a similar issue but you have one project for both your server and client code then I am not entirely sure what may be the cause. I hope this helps!

Oh, it's a pity. Btw, I don't use a custom connect, so a single call to NetworkManager.StartClient calls connect, ready and addplayer methods. Please note: this spawns on both client & server. Only server can control it When I create a prefab at the server, it creates at the client side! However, only server can move the object so the client see its movement. But not vice versa. And I'm going crazy about this.

I had no idea that StartClient called ClientReady... You saved me from a lot of potential headaches down the line. I am curious how the client is connecting to the server without the MatchInfo parameter being set though. Does is assume the connection is local if that parameter has not been set? Also, NetworkServer.Spawn sends a networked object to all clients from the server. So you wouldn't need the OnGui code on the client correct? Since that code would only work on the server? If I'm mistaken I would love to know so that I don't make that mistake when I start messing with that stuff.

1) You're right. It uses a local connection with default settings. If you go to NetworkManager and set a log level to developer, you will see all internal unet calls. 2) Right, OnGui at the clients' side is senseless.