I’m trying to make a monopoly copy, kind of have the base game with 1 player moving around and buying tiles, i have a separate from player script that only contains a private list of tiles to know which tile im standing on and a public function to return the tile. Now that i’ve added networkmanager and other scripts for relay and netcode to work, my player code gives a NullReferenceException on every time i try to use that function. The function was working just fine before the relay stuff and i kind of lost track of where it even went wrong. The list fills in just fine, i’ve tried to debug log it from inside the Start() of tiles code.
I`m using NetworkBehaviour for my player and a MonoBehaviour for the tile script
Tiles code:
[SerializeField]private List<GameObject> tiles;
private void Start()
{
tiles = new List<GameObject>();
tiles.Add(GameObject.Find("Start_Tile"));
...(this is filled with .Add and find)
}
public GameObject getTile(int num){
Debug.Log("Your tile:" + tiles[num]); // This debug isn't even getting called
return tiles[num];
}
}
Player code part:
[SerializeField]private Tile_Controller tiles;
...
public override void OnNetworkSpawn()
{
tiles = GameObject.Find("Tile_Controller").GetComponent<Tile_Controller>();
...
else{
Current_Id += roll;
Debug.Log("You rolled: " + roll1 + ", " + roll2); // This debug shows ok data
Debug.Log(tiles.getTile(Current_Id)); // Here is the error line
transform.position = new Vector3(tiles.getTile(Current_Id).transform.position.x, 0.11f, tiles.getTile(Current_Id).transform.position.z);
}
I’ve already tried making
GameObject tile = tiles.getTile(Current_Id);
So I`m pressing the roll button → Debug shows that i’ve indeed rolled some points and inspector shows that my Current_Id is not something stupid → player code function doesn’t even enter the tile script function because there’s no message from debug inside the getTile()
Also, i have a text field that has to change the text from player code but gives the same error
[SerializeField]private TextMeshProUGUI Money_Display;
...
if(Current_Id + roll >= 40){
Current_Id = (Current_Id + roll) - 40;
Debug.Log("You got 2000 for passing the start");
money += 2000;
Money_Display.text = "" + money;