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
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);
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.
In my case the lag was caused by Mono build in player settings. IL2CPP build fixed it. And I disabled the “Raycast Target” for the objects which doesn’t need it. This will reduce the EventSystem effort/Update.