Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How Do I Hide Screens and Prevent Them From Responding to Events?

Discussion in 'UI Toolkit' started by ShokWayve, Jul 26, 2023.

  1. ShokWayve

    ShokWayve

    Joined:
    Jan 16, 2013
    Posts:
    117
    I have an application with several screens. I created UI document objects for each screen along with a C# file to manage interactions with the screen. When I want to hide or show them in code I use the display style flex or none. However, the hidden screens still respond to events, and when a button is pressed, the hidden screens display even though they are not supposed to do so.

    For example, the logo screen has no user input and just shows for 3 seconds or so and then the title screen is supposed to show. The title screen then has a click any button capacity to show the home screen. However, if I press a button while the logo screen is showing, the home screen shows as if it was just there listening for events, then the title screen shows.

    With the old UI system, I could use one object to enable or disable all the screens. Is that the best practice here? I thought UI Toolkit was trying to move us away from a component system for UI to more of an event drive web-like approach to UI.

    How do I hide a screen, preclude it from responding to events, and keep hidden when buttons are pressed?

    Thanks!
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
  3. ShokWayve

    ShokWayve

    Joined:
    Jan 16, 2013
    Posts:
    117
    So the full situation is that I am using the new input system and ui toolkit. I attached the new input system to the UI Document game object. Even when the screen was set to display:none, it was still responding to events. My solution was to disable the attached input system whenever the screen was not being shown. This stopped it from responding to events.

    Is what I described the intended approach to using the new input system with UI toolkit? Do you have different or better guidance?

    Thanks!
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    You can continue doing what works for you for now. We have an updated API coming in 2023.2+, that will also remove the dependency on uGUI to run Input System with UI Toolkit. Things should be easier then.
     
    ShokWayve and saskenergy like this.
  5. ShokWayve

    ShokWayve

    Joined:
    Jan 16, 2013
    Posts:
    117
    Great, thanks! I will be on the lookout for it.