[PHOTON] Getting NullReference when theres more players

void Start(){
        killFeedUI = GameObject.Find ("KillFeed");
    }
public void Die(){
        GameObject[] players = GameObject.FindGameObjectsWithTag ("Player");
        foreach(GameObject p in players){
            p.GetComponent <PhotonView>().RPC("SendFeed", PhotonTargets.All, killersName);
        }
        PhotonNetwork.Destroy (gameObject);
    }
[PunRPC]
    public void SendFeed(string killer){
        GameObject newFeed = GameObject.Instantiate (feedPrefab);
        newFeed.transform.SetParent (killFeedUI.transform);
        newFeed.transform.GetChild (0).GetComponent <Text>().text = (killer + " killed " + GetComponent <PhotonView>().owner.NickName);
        newFeed.transform.localScale = new Vector3 (1, 1, 1);
    }

In my code above, so bascially when I die, every player will instantiate a UI to their own canvas. Right now, when there’s only one player in the room, the SendFeed gets called to that one player(me), everything works fine. But if there’s 2 players, I get a nullreference on newFeed.transform.SetParent (killFeedUI.transform); and the the UI gets instantiated infinately. Why is this happening? Everything works fine with one player, why are there problems with multiple?

Debug this some more. You can attach MD or VS to Unity and run this. Both should stop when the nullreference happens and you can look up what value is null. Then think about it why this might be the case.
It’s a game-logic issue more than a network issue.

1 Like

It’s difficult to say for certain going on the code supplied but you probably want to restrict the SendFeed() function to only run on the local player object.

Try adding if(!photonView.isMine) return; as the first line of your SendFeed() function. (you may want to change the SendFeed() script to inherit from Photon.PunBehaviour if it doesn’t already, otherwise you won’t have available the handy cached reference to the PhotonView component.

1 Like