Player ReSpawn Logic

I was learning multiplayer game implementation through Unity Multiplayer system.
So I come across this really good tutorials written for beginners:

Introduction to a Simple Multiplayer Example

From this tutorial, I can’t able to understand this page content:
Death and Respawning

Through this code, in tutorial they are talking about our player will respawn (player will transform at 0 position and health will be 100) and player can start fighting again.

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Collections;
 
public class Health : NetworkBehaviour {
 
    public const int maxHealth = 100;
 
    [SyncVar(hook = "OnChangeHealth")]
    public int currentHealth = maxHealth;
 
    public RectTransform healthBar;
 
    public void TakeDamage(int amount)
    {
        if (!isServer)
            return;
     
        currentHealth -= amount;
        if (currentHealth <= 0)
        {
            currentHealth = maxHealth;
 
            // called on the Server, but invoked on the Clients
            RpcRespawn();
        }
    }
 
    void OnChangeHealth (int currentHealth )
    {
        healthBar.sizeDelta = new Vector2(currentHealth , healthBar.sizeDelta.y);
    }
 
    [ClientRpc]
    void RpcRespawn()
    {
        if (isLocalPlayer)
        {
            // move back to zero location
            transform.position = Vector3.zero;
        }
    }
}

As per my thinking → All clients are executing ClientRPC so all devices local players will move at the spawn position and health get full.
As per this tutorial → only own player’s spawn position and health get updated.

So why this thing is happening that I can’t able to understand?
Actually RPC get called on all clients then all clients should require to move at start position and get full health.
Please give me some explanation in this.

Hey there,

as far as i understand this the rpc is indeed called at every client, so you got this point right.
But if you take a look at the RpcRespawn() functions content you will notice that there is an if statement checking if the rpc call is called at the objects owner with if(isLocalPlayer). Thus the actual content of the function will only be called at one player even though the function as a whole will be called at every player.

In the end this is ok since the respawn function will probably not be called too often. This way of handling things is not recommended for rpc’s that will be called multiple times per second since you will create way too much network traffic.

Hope this helps.