Dear Unity,
I have a nullpointer exception and am not really sure why I am getting this. I have a script with 2 objects connected to it. Spatula and Fryingpan which I set to nonactive at the initialization of the script start as followed:
if (RecepScenarioObjectHandelerNull())
{
InitializeReceptScenarioObjectHandler();
}
→ Then it initializes like overe here
void Start () {
if (!IfSpatulaAndFryingPanNull())
{
Spatula.SetActive(false);
FryingPan.SetActive(false);
}
}
This works perfectly and disabled the game objects right from the start which I want. But when I want to activate the gameobjects for use with the following function I get a nullpointer:
public bool IfSpatulaOrFyingPanActive()
{
if (IfSpatulaAndFryingPanNull())
{
System.Diagnostics.Debug.WriteLine("One of the objects is null");
}
else if (Spatula.activeSelf == true || FryingPan.activeSelf == true)
{
return true;
}
return false;
}
Even if I do not disable the objects in the beginning the debugging shows me that the objects are null and I have no clue why. I do not move to another scene or close a script.
Side note: I added the gameobjects as publics and added the objects in unity as follows:
Does anyone know what the problem could be?
Kr,