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

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!