Relay NullReferenceException

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;

It’s always the same answer… ALWAYS!!

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Three steps to success:

  • Identify what is null ← any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

Remember the first rule of GameObject.Find():

Do not use GameObject.Find();

More information: https://starmanta.gitbooks.io/unitytipsredux/content/first-question.html

More information: https://discussions.unity.com/t/899843/12

ALSO:

If you have more than one or two dots (.) in a single statement, you’re just being mean to yourself.

How to break down hairy lines of code:

http://plbm.com/?p=248

Break it up, practice social distancing in your code, one thing per line please.

“Programming is hard enough without making it harder for ourselves.” - angrypenguin on Unity3D forums

“Combining a bunch of stuff into one line always feels satisfying, but it’s always a PITA to debug.” - StarManta on the Unity3D forums

Ok, so because im using a player prefab for relay, i can't assign objects with Inspector so i created an empty object that has a script that contains references to needed objects(also just filled the tiles list through the inspector), im finding that object with .FindWithTag() and it seems to work. However, what is interesting is that i could walk on tiles normally but when i wanted to buy them, it gave me the same error about tiles nullreference. What i found out was a ```
if(!IsOwner) return;

line that my walk() function started with, so i added that line on the start of the buy() function and it actually works, no nullreference errors.
Any idea what this whole thing is? I don't know much about relay, just watched a video about netcode and relay from CodeMonkey and i don't think he really explained this line, all i remember is him putting it at a start of Update() which i don't even have.

https://www.youtube.com/watch?v=3yuBOB3VrCk
Timecode:16:30