When I press a button or activate an Event System trigger there is a spike of lag (200 ms on my galaxy s2).
After the first initial lag spike the lag goes away and I can press the button freely with no lag spikes.... Why is that?
I even tested this on an empty scene; I placed a button on an Image. I have a cube rotating thru animation. When I build to my android phone and press the button there's a lag spike (cube freezes briefly then continues rotating as usual).
Is it because of my old phone? Since it only lags on the first touch I don't think it is...
Am I doing something wrong? Should I just poll for Input.GetTouches instead?
Using Unity 5.0.1f1
I have the same problem on my low-end phone, but not on my tablet. The tablet does have a tiny spike, just not as noticeable as the one on the phone, but it does seem like faulty optimization in the UI system on Unity's part.
Oh, that's unfortunate :( Still no progress on my end
I'm getting exactly the same issue with Unity 5.1.2 on my galaxy S3. Did you find any solution. It's horrible.
The only solution I found was to have the user press a button such as a "Start Game" button to mitigate the initial lag.
The problem is not on EventSystem, this occurs when you have a Text GameObject that loads a font for the first time, so probabily after you press the button you create or have a GameObject that has a Text component. The lag is due that it has to load the font into memory for the first time. Check Incl. Font Data for the Font in the Fonts folder.
It doesn't work for me. No Text component, adding a custom Font with Incl. Font Data enabled, completely removing all gameobjects with text and it still lags... Profiler again shows EventSystem.Update() with some huge spike and Garbage allocation.
Answer by NarkomDe
Jan 24, 2016 at 09:56 PM
This doesn't fully solve a problem, but reduce performance spike twice for me. I'm creating and sending button click event via a script, and on the button ignore first click. public Button button;
var pointer = new PointerEventData(EventSystem.current); // pointer event for Execute
ExecuteEvents.Execute(button.gameObject, pointer, ExecuteEvents.pointerEnterHandler);
ExecuteEvents.Execute(button.gameObject, pointer, ExecuteEvents.submitHandler);
ExecuteEvents.Execute(button.gameObject, pointer, ExecuteEvents.pointerDownHandler);
ExecuteEvents.Execute(button.gameObject, pointer, ExecuteEvents.pointerUpHandler);
Thanks NarkomDe, this does help with the initial spike. I Wish this problem would be fixed already ( among many others, too :P )
Answer by Bruno R. Marcos
Nov 19, 2015 at 12:02 PM
What does a deep profile say?
Believe it or not it tells me less, It just says BehaviourUpdate without the expandable arrow. (I had a Test script that did nothing, so I removed it )
I had a 200ms lag on the first button click. I had to disable almost all GameObjects until I found that this was causing it, after that now is smooth. Sorry this didn't help you.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
8 People are following this question.
EventSystem not detecting all UI elements
How to access other Scripts and Components
Touch Input only working on Unity Remote
How do I intercept touch events in Android native code?
Touch are laggy on ipod touch(4th gen.)