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!
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() ?
yes, I tried setActive(false) in Start().
It’s same.
Sorry, no idea, then…
Did you have any luck with this? I have tried the same thing. I also have tried a few other methods, no dice.
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
Thanks, this worked!