I can't get player to respawn over network.

I am using a Unity Platforming Demo and can not get the player to respawn to the proper place over the network. The funny thing is, every once in a while, maybe 1/8, he’ll respawn (which is just setting his position) works. For the most part, the player’s position ends up being where he was last (which is falling offscreen)

I am using the a server-side kill trigger, and a ClientRPC to respawn. I am setting the position both in the server script and client script. I’ve tried many enumerations and combinations, even setting the transform of the rigid body or collision body transforms.

It seems that nothing gets this to work properly, and the player always ends up falling offscreen.

Here is my clientRPC for respawning.

[ClientRpc]
	public void RpcRespawn (Vector3 pos)
	{
		Debug.Log("player respawned at position: " + pos.ToString());
		gun.enabled = true;
		playerControl.enabled = true;

		health = 50f;
		healthBar.enabled = true;
		UpdateHealthBar();

		gameObject.transform.position = pos;
		respawned = true;
	}

	[ClientRpc]
	public void RpcShutdown()
	{
		Debug.Log("player shutdown");
		gun.enabled = false;
		playerControl.enabled = false;

		healthBar.enabled = false;
	}

Also, here is my serve-rside code

 IEnumerator ReloadGame()
    	{			
    		// ... pause briefly
    		while (timeToRespawn.Count > 0)
    		{
    			yield return new WaitForFixedUpdate();
    			for(int i = 0; i < timeToRespawn.Count; i++)
    			{
    				timeToRespawn *-= Time.deltaTime;*

_ if (timeToRespawn < 0)_
* {*
* //MAKE RPC CALL HERE!*
* Debug.Log("Time to respawn count: " + timeToRespawn.Count.ToString() + " ip address: ");*
_ GameObject player = objsToRespawn*;*_

* startPosition = NetworkManager.singleton.GetStartPosition().transform.position;*
* player.GetComponent().RpcRespawn(startPosition);*
* player.transform.position = startPosition;*
* timeToRespawn.RemoveAt(i);*
* objsToRespawn.RemoveAt(i);*
* //Debug.Log(“Player Respawned” + player.name + "at position: " + startPosition.ToString());*
* break;*
* }*
* }*

* }*
* }*

I’m not sure why you call

player.transform.position = startPosition;

after

player.GetComponent<PlayerHealth>().RpcRespawn(startPosition);

since you’re setting the Gameobjects’ position in the RpcRespawn method.

I’m not sure how to fix your problem, but maybe showing you my working respawn script will help you out:

 // Called on server
 foreach (GameObject player in getPlayerGameObjects())
 {
     PlayerStats pStats = player.GetComponent<PlayerStats>();
     PlayerState pState = player.GetComponent<PlayerState>();
     // Some stat resets that need to happen on server to the client
     pStats.isDead = false;
     pStats.health = pStats.maxHealth;
     // Client side stuff that needs to be called for respawning
     pState.RpcPlayerHandleSpawn();

     // And finally set the players' position
     SpawnPlayerToPosition(player, spawnPoints*.transform.position);*

}
[Server]
void SpawnPlayerToPosition(GameObject player, Vector3 pos)
{
player.GetComponent().RpcSetPlayerPosition(pos);
}
[ClientRpc]
public void RpcSetPlayerPosition(Vector3 pos)
{
ctm.targetPosition = pos;
transform.position = pos;
}
[ClientRpc]
public void RpcPlayerHandleSpawn()
{
if (!isLocalPlayer)
return;
// Other client side stuff etc…
GetComponent().enabled = true;
GetComponent().enabled = true;

}
Hope that helps!