Photon RPC doesn't broadcast properly.

I'm trying to sync player's animation through network by using Photon RPC, but it doesn't work.

Player can have 2 weapons and using only one of them once. So when player switch the weapon, I'll broadcast that which weapon have to switch like this:
public void SetWeapon(Weapon weapon) {
	photonView.RPC("RPCSetWeapon", PhotonTargets.Others, weapon);
}

[PunRPC]
void RPCSetWeapon(Weapon weapon) {
	// Switch Animation
	characterAnimator.SetBool(weapon.ToString(), true);
}
It's FPS game so I don't have to set animator in local player, so used PhotonTargets.Others.

Also sync firing and reloading animations has same logic:
public void PlayFireAnimation() {
	photonView.RPC("RPCPlayFireAnimation", PhotonTargets.Others);
}

[PunRPC]
void RPCPlayFireAnimation() {
	characterAnimator.SetTrigger("Firing");
}

public void PlayReloadAnimation() {
	photonView.RPC("RPCPlayReloadAnimation", PhotonTargets.Others);
}

[PunRPC]
void RPCPlayReloadAnimation() {
	characterAnimator.SetTrigger("Reloading");
}
But when I run this game, nothing happens and only I got is these warning messages:

> animator is not playing an animatorcontroller

So I checked which object got RPC like this:
void RPCSetWeapon(Weapon weapon) {
	if(photonView.isMine) {
		print("IS LOCAL PLAYER, SKIP IT.");
		return;
	}
	else {
		print("IS NOT LOCAL PLAYER.");
	}
But it always printing "IS NOT LOCAL PLAYER.". Seriously, I don't know why this happens, am I misunderstanding use RPC or something?

Please let me know how do I fix this, thanks.

Best Answer

  • modernator
    Answer ✓
    Nevermind, it solved. It caused from calling RPC from wrong Player.

Answers

  • modernator
    Answer ✓
    Nevermind, it solved. It caused from calling RPC from wrong Player.