- Home /
SpawnWithClientAuthority Player object is not a Player
I am trying to use the new features in 5.2 that allow for client authority spawning. I am getting some errors on the client that I can't figure out.
Here is the function
public void makeBoosterItem (Vector3 pos, float temp, int biome){
float Level = Vector3.Distance (pos, spawnPoint);
GameObject Hr = Instantiate (healthRoot) as GameObject;
Hr.transform.position = pos;
Hr.GetComponent<Item> ().setNetworkOwner (player);
Hr.GetComponent<Item> ().setLevel (Level);
NetworkServer.SpawnWithClientAuthority (Hr,player);
}
Now I garentee you that the player is the correct player. I have checked the network owner varible in my other script and it is the correct game object. However whenever I log on as the client I get this error SpawnWithClientAuthority Player object is not a Player. Its referring to the last line of that function. I don't understand. I am giving it a player object. It works on the server fine. Does anyone know more about the restrictions involved when using SpawnWithClientAuthority? does it have to be used from the player object? I can't find the documentation on the function.
Answer by sharat · Oct 16, 2015 at 11:36 PM
The extra restrictions/easy mistakes for using SpawnWithClientAuthority() from my experience are:
You must run this code on the Server. Check if NetworkServer.active is true.
The prefab for the item specified still needs to be included in the NetworkManager list of spawnPrefabs. You can either add it to the list directly in the editor or dynamically via ClientScene.RegisterPrefab()
The object should have local player authority set to true.
You have to pass in the object instantiated on the server to the function, not the prefab.
I think that the player needs to have been set to ready first. But I haven't really tested this one.
I believe your problem is the first one, running from the Client instead of the server. Try using a [Command] or a NetworkMessage to get the Server to instantiate it for you.
Awesome thank you. I was able to just change the function to a command and that fixed the problem
[Command] public void CmdmakeBoosterItem (Vector3 pos, float temp, int biome){ float Level = Vector3.Distance (pos, spawnPoint); GameObject Hr = Instantiate (healthRoot) as GameObject; Hr.transform.position = pos; Hr.GetComponent ().setNetworkOwner (player); Hr.GetComponent ().setLevel (Level); NetworkServer.SpawnWithClientAuthority (Hr,player); }
Please repeat what you wrote in <> on Hr.GetComponent ().setNetworkOwner (player);
Ok so I am having a new issue now. I have switch most of the things that the object i'm spawning does over to the client by using if (hasAuthority) ins$$anonymous$$d of if(isServer)
However now I am getting this error from the server every time a client attempts to spawn something. found no receiver for inco$$anonymous$$g command. The server and the client should have the same NetworkBehaviour instances.
ok i guess for some reason the health wasn't getting set on the client anymore. Probably has something to do with it being a syncvar. If you don't $$anonymous$$d could you quick go over how client authority sync vars work. Do I need to use a command to change them or can I just say if is server to modify them. I'm guessing they work the same way as the player sync vars do?
Your answer
Follow this Question
Related Questions
zombie network spawn! help" 0 Answers
Player Prefab on Lobby Managers? 5 Answers
Spawning a new player instance (UNET) 3 Answers
How to to spawn player, according to id? 0 Answers
Netcode [Command] Issues .. no errors, just not working. 1 Answer