Hello everyone. Making a turn-based strategy game. #30 string in HexPoint class’ constructor get NullReferenceException: Object reference not set to an instance of an object
I disabled this object in Unity, but now when this string (HexInfo.enabled = false;) is commented project crushes. Having no idea why.
[64107-scripts.zip|64107]

Hello, @Kelborn.

In HexPoint’s constructor:

		public HexPoint()
		{
			// ...
			HexInfo = GetComponent<MeshRenderer> ();
			// ...
			HexInfo.enabled = false;
                        // ...
		}

The NullReferenceException error is caused by the failure to initializeHexInfo by calling GetComponent< MeshRender >(). This is because there isn’t a MeshRender component attached to the game object of HexPoint component.

To fix this error, attach a MeshRender component to the game object that has the HexPoint component.

Call GameObject.SetActive to activate or deactivate a game object. Here is the documentation:

Regardless, this should never crash the editor