I’m assuming the issue is probably related to the execution order of things.
I have a script for example
public partial class TerrainStuff
{
public class TerrainDisplacement : MonoBehaviour
{
private float _brushSize = 100f;
public float brushSize
{
get
{
return _brushSize;
}
set
{
_brushSize = value;
//do some other stuff
}
}
}
which is called on and stored in a static variable
public class MapManager : MonoBehaviour
{
public static TerrainStuff.TerrainDisplacement terrainDisplacement;
private void Start()
{
terrainDisplacement = gameObject.AddComponent<TerrainStuff.TerrainDisplacement>();
}
}
and then i have another script where I am trying to access the “brushSize” via the static variable
public class FallingDebris : MonoBehaviour
{
private void Start()
{
Debug.Log(MapManager.TerrainDisplacement.brushSize);
}
}
When trying to run this, why do i get a NullReferenceException Error?
“Object reference not set to an instance of an object”
Am i misunderstanding the execution order or something? I’m trying to figure out how the Start() works a little more because moving the Debug.Log() to an update works absolutely fine.
Thanks in advance for any info