Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Unity UI SetActive(true) lag Problem

Discussion in 'UGUI & TextMesh Pro' started by asakurayonik, May 8, 2017.

  1. asakurayonik

    asakurayonik

    Joined:
    May 8, 2017
    Posts:
    3
    I have two buttons under a panel. The "active" is false as default. Every time I press "Esc", those two button will pop out by SetActive(true) of this panel.
    However, the first time those two button pop out, the screen will have lag. The second, third time and so on will have no lag.
    I want to know is there a way to solve this problem? Or I need to use another method to show the pop out UI?
    Thanks in advance!
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Are you just checking in Update() for 'esc' ?

    Other than that, I'm not sure if this will help as I've not come across this before, but if as you say subsequent 'esc' hits don't cause lag, is there any improvement if you start with them enabled and SetActive(false) in Start() ?
     
  3. asakurayonik

    asakurayonik

    Joined:
    May 8, 2017
    Posts:
    3
    yes, I tried setActive(false) in Start().
    It's same.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Sorry, no idea, then..
     
  5. asakurayonik

    asakurayonik

    Joined:
    May 8, 2017
    Posts:
    3
  6. KarlN

    KarlN

    Joined:
    Nov 27, 2014
    Posts:
    14
    Did you have any luck with this? I have tried the same thing. I also have tried a few other methods, no dice.
     
  7. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    I see this too. The first time UI is set active it seems to do a lot of allocations and CPU work, creating objects and probably laying things out. I've had some success working around this in the past by having the objects active and then setting them to inactive when the game starts.

    You could also try putting a CanvasGroup on the parent panel, leave the panel as active, set the panel alpha to 0, and set interactable to false. The when you want to enable it set the alpha to 1 and set interactable to true.

    -sam
     
    gersonbellodegoes likes this.
  8. tskipurishvilimakrina

    tskipurishvilimakrina

    Joined:
    Nov 20, 2021
    Posts:
    7

    Thanks, this worked!