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.

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.