Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Managing State and Input in Unity

Discussion in 'Scripting' started by VMS_Lab, Sep 14, 2015.

  1. VMS_Lab

    VMS_Lab

    Joined:
    Dec 31, 2013
    Posts:
    3
    Greetings

    My team and I are developing a visualization application using Unity. We are about to design the user interface and user experience and I wanted to ask other Unity users if they had any best practices that the employ when managing input state.

    For example: We’re in the 3D portion of our application and we press F10 to open a menu. What is the best way to focus solely on that menu and block all other input until that menu is closed?

    Another example: We want to use drop down menus such as those seen in Windows (File, Edit, Assets, etc). What is the most efficient way to make sure that drop down rolls back up if I open it and then change my mind and click somewhere else?

    I’ve read some thoughts on the forums here about having all of your input go through a manager or having a script on every clickable object that checks a manager the see whether it can respond to input. Some even suggest extending and modifying the Standard Input Module. Does anyone have any practical experience using such methods? Or better ways to manage state and input in Unity?

    Thanks.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I typically use two methods in combination.

    A manager class can be used to track the current menu and store the previous menus. This allows for the user to negotiate backwards easily.

    Then I'll put an invisible UI object behind each menu and use that to block input to the rest of the game, as well as detect off menu clicks.