Photon Network variables on spawn not set on client

I have the following method to spawn a GameObject (which is being fired on RMB).

void SpawnProjectile(string SpellName)
	{
		Vector3 spawnLocation = transform.Find("ProjectileSpawnLocation").transform.position;
		
		GameObject go = (GameObject)PhotonNetwork.Instantiate(SpellName, spawnLocation, transform.rotation, 0);
		
		Projectile projectile = go.GetComponent<Projectile>();
		
		projectile.totalRange = projectile.BaseRange + spell.getSpellLevel();
		projectile.totalDamage = projectile.BaseDamage + spell.getSpellLevel();
	
		go.name = SpellName;
		projectile.Instigator = gameObject;
		
		projectile.enabled = true;
	}

This works fine for the master client, however, when I do this on a client, variables aren’t right and it gives errors like e.g. Null reference on Instigator, because I’m checking on the OnCollisionEnter if the Instigator is not equal to the collision object.

What can I do to make this work for all connected clients? Thanks in advance!

You’re only setting the variables on the master client, because this function is only being called on the master client. To send the same information to the rest of the players in the game, you’re going to have to send them a network message (an RPC).

You can create an RPC function by putting the [PunRPC] tag above it, and then calling it on the master client by calling GetComponent().RPC(“rpcFunctionName”, PhotonTargets.Others, spellName, totalRange, totalDamage, SpellName, instigator.GetComponent().owner), or something along those lines.

Just send the variables you want to set as arguments through the RPC call, and all the other clients (or all clients including the master client if you use PhotonTargets.All instead) will have all of the variables, and can set the projectile’s variables themselves.