Toggling GUI textures show/ disappear

I am working on a Game and am having a bit of an issue with some NGUI buttons. When my game starts I want it to show only one button, that, when the user clicks on it the button goes away and then more buttons show up on the screen. The issue is that when I click on the button, it disappears like it should but it spams an error message saying: game object not set to an instance of an object.

Can anyone help me figure what do I need to do in order to get my buttons showing up correctly? Many thanks in advance!

This is the code I have so far:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CameraNavigationManager : MonoBehaviour {
    enum navigationStates { none, translation, rotation, exitNavigation }
    navigationStates currentNavigationState = navigationStates.none;

    private float speed = 1.5f;
    private float direction = 1;
    private float camerDirection = 0;

    void Start()
    {
        GameObject.FindGameObjectWithTag("ExitNavigation").SetActive(false);
        GameObject.FindGameObjectWithTag("EnterRotation").SetActive(false);
        GameObject.FindGameObjectWithTag("EnterTranslation").SetActive(false);
        
        foreach (var x in GameObject.FindGameObjectsWithTag("ZoomInOut"))
        {
            x.SetActive(false);
        }
        foreach (var x in GameObject.FindGameObjectsWithTag("Rotation"))
        {
            x.SetActive(false);
        }
        foreach (var x in GameObject.FindGameObjectsWithTag("Translation"))
        {
            x.SetActive(false);
        }
    }
    void OnGUI()
    {
        switch (currentNavigationState)
        {
            case navigationStates.translation:
                break;
            case navigationStates.rotation:
				DisplayButtons();
                break;
            case navigationStates.exitNavigation:
                break;
            case navigationStates.none:
                break;
        }
    }

    public void ClickEnterNavigationButton()
    {
        currentNavigationState = navigationStates.rotation;
    }
	public void DisplayButtons()
    {
        GameObject.FindGameObjectWithTag("EnterNavigation").SetActive(false);
		GameObject.FindGameObjectWithTag("EnterTranslation").SetActive(true);
        
        foreach (var x in GameObject.FindGameObjectsWithTag("ZoomInOut"))
        {
            x.SetActive(true);
        }
        foreach (var x in GameObject.FindGameObjectsWithTag("Rotation"))
        {
            x.SetActive(true);
        }
        foreach (var x in GameObject.FindGameObjectsWithTag("Translation"))
        {
            x.SetActive(true);
        }
    }
}

If I’m recalling correctly, the FindGameObject methods will not detect objects that are disabled. So once you disable them you will fail to find the on subsequent checks.

Also you should avoid doing repeated searches for items. I’d suggest searching for your buttons at the start, cache the references to those game objects, and then use those references to activate/deactivate the objects.

Also if you are doing one time search and action on objects like this, it can really help to first search for the object, and then check if its null before accessing methods or variables of it, that way you can easily throw in meaningful logs to let you know that it failed to find the object.

Edit: Also it looks like you’re doing a lot of unnecessary work in your gui calls. every frame you’re going to be calling the SetActive method to turn items on and off even if they are already in the desired state. I’d suggest swapping this to a more event driven pattern where you have an event (be it external event or a button press) that triggers the setting of active and inactive.