NullReferenceException: Object reference not set to an instance of an object when calling RPC
Hello! I am currently working on a small school project and ran into this issue. I can't for the life of me figure out where I went wrong. Some assistance would be much appreciated! Sorry in advance for the spaghetti. Still learning!
NullReferenceException: Object reference not set to an instance of an object
TeamManager.Set () (at Assets/Scripts/TeamManager/TeamManager.cs:77)
UnityEngine.Events.InvokableCall.Invoke () (at <e98ed0368295432e8c11e52d6243ee11>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <e98ed0368295432e8c11e52d6243ee11>:0)
NullReferenceException: Object reference not set to an instance of an object
TeamManager.Set () (at Assets/Scripts/TeamManager/TeamManager.cs:77)
UnityEngine.Events.InvokableCall.Invoke () (at <e98ed0368295432e8c11e52d6243ee11>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <e98ed0368295432e8c11e52d6243ee11>:0)
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Photon.Pun; public class TeamManager : MonoBehaviourPun { public string houseSelected; public string teamSelected; public string ID; public bool ready; public int readyCount; [SerializeField] private Button glasheen; [SerializeField] private Button reed; [SerializeField] private Button daffey; [SerializeField] private Button fitzgerald; [SerializeField] private Button hider; [SerializeField] private Button seeker; [SerializeField] private Button set; PhotonView pv; List<TeamManager> teamUserData; Color original = new Color(250, 250, 250); private void Start() { teamUserData = new List<TeamManager>(); pv = GetComponent<PhotonView>(); } private void Update() { Debug.Log("ID: " + ID + " / House: " + houseSelected + " / Team: " + teamSelected + " / ready: " + ready); foreach (TeamManager a in teamUserData) { Debug.Log("ID: " + a.ID + " / House: " + a.houseSelected + " / Team: " + a.teamSelected + " / ready: " + a.ready); } } public TeamManager (string UserID, string house, string team, bool isReady) { ID = UserID; houseSelected = house; teamSelected = team; ready = isReady; } [PunRPC] void RoomReady(string sentID, string sentHouse, string sentTeam, bool ready) { UpdateTeamData(sentID, sentHouse, sentTeam, ready); SetReady(1); } void UpdateTeamData(string updateID, string updateHouse, string updateTeam, bool isReady) { teamUserData.Add(new TeamManager(updateID, updateHouse, updateTeam, isReady)); } void SetReady(int num) { readyCount += num; if (readyCount == PhotonNetwork.CurrentRoom.MaxPlayers) { gameObject.SetActive(false); } } public void Set() { ready = true; pv.RPC("RoomReady", RpcTarget.AllViaServer, pv.Owner.UserId, houseSelected, teamSelected, true); } public void HouseSelect(string house) { houseSelected = house; HouseButtonCheck(); } public void TeamSelect(string team) { teamSelected = team; TeamButtonCheck(); } private void HouseButtonCheck() { ColorBlock colors; if (glasheen.name == houseSelected) { colors = glasheen.colors; colors.normalColor = glasheen.colors.highlightedColor; glasheen.colors = colors; } else { colors = glasheen.colors; colors.normalColor = original; glasheen.colors = colors; } if (reed.name == houseSelected) { colors = reed.colors; colors.normalColor = reed.colors.highlightedColor; reed.colors = colors; } else { colors = reed.colors; colors.normalColor = original; reed.colors = colors; } if (daffey.name == houseSelected) { colors = daffey.colors; colors.normalColor = daffey.colors.highlightedColor; daffey.colors = colors; } else { colors = daffey.colors; colors.normalColor = original; daffey.colors = colors; } if (fitzgerald.name == houseSelected) { colors = fitzgerald.colors; colors.normalColor = fitzgerald.colors.highlightedColor; fitzgerald.colors = colors; } else { colors = fitzgerald.colors; colors.normalColor = original; fitzgerald.colors = colors; } } private void TeamButtonCheck() { ColorBlock colors; if (hider.name == teamSelected) { colors = hider.colors; colors.normalColor = hider.colors.highlightedColor; hider.colors = colors; } else { colors = hider.colors; colors.normalColor = original; hider.colors = colors; } if (seeker.name == teamSelected) { colors = seeker.colors; colors.normalColor = seeker.colors.highlightedColor; seeker.colors = colors; } else { colors = seeker.colors; colors.normalColor = original; seeker.colors = colors; } } }
0