Initial screen tap pauses animation

I’m working on a 2D game where tapping at the right moment causes sprites to explode with a particle effect. For some reason, the first tap causes a noticeable pause in the sprite animation. The sprites appear frozen for a few frames, then suddenly jump to where they should have been. The pause happens regardless of whether the particle effect gets triggered. I also tried disabling sound effects completely to verify they weren’t related and they weren’t. This only happens on the very first tap and happens even if I let the game sit idle for a minute or two before tapping. The game runs smoothly after the first tap. It only happens on Android (haven’t ported to iOS yet) and not in the Unity editor. I’m using an OnMouse event handler to detect the tap which triggers a warning about performance when I build for Android, but all the forum posts I’ve found on it say it’s a false positive. Any idea what might be causing the pause?

Could be the particle needs “pre-warmed” somehow, to get it loaded into memory, before actually using it the first time…

Just a guess though, not sure if that could be the problem or not :frowning:

It’s definitely not related to the particle effects because the pause happens even if you miss-time the initial tap and fail to cause any sprites to explode. It definitely seems that something is being cached on that initial tap, though, since everything’s fine after that. I’m wondering if there might be something to the OnMouse warning I get during build. Maybe something gets loaded into memory the first time the event is triggered?

I’m pretty sure I’ve eliminated the OnMouse events as a potential cause. I replaced every instance of Input.GetMouseButtonUp(0) with a call to this function:

// Check for screen taps
public bool CheckTap() {
bool screenTap = false;
#if UNITY_EDITOR
if (Input.GetMouseButtonUp (0))
screenTap = true;
#else
if (Input.touchCount == 1 &&
(Input.GetTouch (0).phase == TouchPhase.Ended || Input.GetTouch (0).phase == TouchPhase.Canceled))
screenTap = true;
#endif
return screenTap;
}

I still get the OnMouse error when building, though, and the problem is still there.

I have more info but still no solution. This only happens on Android, not iOS, and the profiler says the cause is EventSystem.Update(). I’ve come across a number of other posts reporting the same problem on Android going back a few years, but no reported solution works for me. One suggestion was to send a fake tap event to the EventSystem in Start() using ExecuteEvents.Execute which didn’t work for me. I also tried it on the first run of Update(). Someone else suggested it was related to loading a font for the first time, but calling the method to render the font both in Start() and Update() had no effect. This is the method I used to try to fake the touch action:

void FakeTouch() {
// Fake initial touch to initialize the EventSystem for Android
GameObject fakeTouchObj = GameObject.Find(Constants.fgCanvasName);
PointerEventData pointerData = new PointerEventData (EventSystem.current);
ExecuteEvents.Execute (fakeTouchObj.gameObject, pointerData, ExecuteEvents.pointerDownHandler);
ExecuteEvents.Execute (fakeTouchObj.gameObject, pointerData, ExecuteEvents.pointerUpHandler);
}

What version of unity do you use?

Edit: some other thoughts, do you build il2cpp? Or just regular mono backend?

I’m currently on 5.5.3f1 and was on 5.5.0f3 when I started the project. I’ve had the issue on both versions. I’m using the Mono backend. I haven’t tried IL2CPP yet, but maybe I’ll give that a shot next.

Thanks, MD_Reptile, IL2CPP appears to have solved it!!! I’ll need to test all aspects of the game, but so far everything appears to be working as it should. :slight_smile:

1 Like

Awesome, glad you got it working! Good luck.