Built in method to check if Start function was already called?
Consider an object of this class:
public class Interactable : MonoBehaviour {
private List<Object> list;
public void Start() {
// Initialize multiple variables
list= new List<>();
list.Add(new Object());
}
public void Select() {
// Uses initialized variables, so it needs to be called after Start()
Debug.Log(list[0]);
}
}
The Select()
method is called whenever player looks at the Interactable
object and is called in a different script. It works fine most of the time, but when the object spawns right in front of the player, the Select()
is called before Start()
and it results in NullReferenceException
, as the variables are not initialized yet (in this example list == null
). I cannot use Awake()
function for initialization.
My approach was to create a bool isInitialized = false;
which would be changed to true
in Start()
, but I was wandering if there is a built-in method to find if Start
was called?
Your answer
Follow this Question
Related Questions
How to change baked lighting when scene loads? 0 Answers
Why does my start function not work? 1 Answer
Help for Restart Level 0 Answers
Start function dont work 1 Answer
What to do first? 4 Answers