Object reference not set help


I am making some kind of multiplayer menu. I need to access a part in a script from another GameObject. It is a variable called “hostData”. Of some odd reason, that can’t be referenced. I did some testing with “Debug.Log(networkScript.hostData == null);” and it gives me true. That is not good. Everything else can be accessed. Why does this happen?

How I make a reference to the script:

void Start () {
	GameObject networkManager = GameObject.FindGameObjectWithTag ("Manager-Network");
	networkScript = networkManager.GetComponent<NetworkScript> ();

How the variable looks like in the network script:

public HostData[] hostData;

Please tell me what is wrong!


Try using this instead:

using System.Collections.Generic;


public List<HostData> hostData = new List<HostData>();

This is much easier and more powerful to manage. And, this will definitely not be null.

I found the problem. This was VERY stupid of me. I had to contact my master server and I never did that. I had the function but never contacted the master server. So I added “ContactMasterServer();” when I press multiplayer or whatever to open up the server browser. Simple as that.