Friday, August 12, 2022
HomeGame Developmentunity - Inactive sport objects nonetheless returning true when querying .activeInHierarchy

unity – Inactive sport objects nonetheless returning true when querying .activeInHierarchy


I am within the strategy of organising keyboard navigation for my sport. I am having an issue the place keybinds that ought to solely work whereas particular sport objects are lively are firing on a regular basis.

Screenshot of DebugLog & Hierarchy.
enter image description here

Right here is the code for the keybind management:

utilizing UnityEngine;

public class KeyboardControl : MonoBehaviour
{
    public GameObject mainMenuButtonContainer;
    public GameObject typingContainer;

    UIManager ui;
    [SerializeField]
    EmailManager em;
    [SerializeField]
    DBManager db;

    personal void Awake()
    {
        ui = GetComponent<UIManager>();
    }

    personal void Replace()
    {
        if (!typingContainer.activeInHierarchy)
        {
            CheckKeybind();
        }        
    } 
    
    void CheckKeybind()
    {
        // Predominant Menu Navigation
        if (mainMenuButtonContainer.activeInHierarchy)
        {
            Debug.Log("Predominant menu buttons lively? : " + mainMenuButtonContainer.activeInHierarchy);
            if (Enter.GetKeyUp(KeyCode.S))
            {
                ui.StoryMode();
            }
            if (Enter.GetKeyUp(KeyCode.I))
            {
                em.ShowInbox();
            }
            if (db.freeplayList.Depend > 0 && Enter.GetKeyUp(KeyCode.F))
            {
                ui.FreePlay();
            }
            if (Enter.GetKeyUp(KeyCode.T))
            {
                ui.Stats();
            }
            if (Enter.GetKeyUp(KeyCode.E))
            {
                ui.Settings();
            }
            if (Enter.GetKeyUp(KeyCode.C))
            {
                Debug.Log("Pressed Credit Keybind");
            }
            if (Enter.GetKeyUp(KeyCode.X))
            {
                ui.ConfirmQuitRequest();
            }
        }

        // E mail Panel Navigation
        if (inboxPanel.activeInHierarchy)
        {
            if (Enter.GetKeyUp(KeyCode.C))
            {
                em.HideInbox();
            }
            if (inboxNextButton.activeInHierarchy && Enter.GetKeyUp(KeyCode.N))
            {
                em.NextEmail();
            }
            if (inboxPrevButton.activeInHierarchy && Enter.GetKeyUp(KeyCode.P))
            {
                em.PreviousEmail();
            }
        }

    }
}

I’ve tried:

  • utilizing activeSelf as an alternative of activeInHierarchy.
  • transferring the keybind checks into their very own operate, out of replace (present state).

The conditional examine for typing container in replace works, because the keybinds are usually not registered if the typing container is lively, however the inverse appears to not be true for the mainMenuButtonContainer.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments