Error finding photonPlayer

Hi, I have this code:

PhotonPlayer target = PhotonPlayer.Find(hit.collider.gameObject.GetComponent<PhotonView>().viewID.ID);

That have the function to find the PhotonPlayer that I have attacked.

This is called after that a RayCastHit hit the player,

Debug.Log("Target Name: " +;

says correctly the name of the player, but

Debug.Log("Target: " +;

says a NullReferenceException: Object reference not set to an instance of an object

I think that there is an error while I’m finding the player, any suggest?

P.S. There is a photonView attached to the Player prefab.


For questions on Photon please visit the ExitGames boards, the Photon Unity Networking category in this case

100% this won’t be helpful considering it was posted 2 years ago; try an if statement before whatever you collide with is set as a PhotonPlayer.targer, like

if (hit.collider.gameObject.GetComponent<PhotonView>().viewId.ID != null) {

//Do something

} else {

Debug.Log ("Sum Ting Wong!");