I'm working on a simple 2D game. When I mean simple, it is really that simple.
It testes the player's reflexes.
I work on Unity 2017.3.0f3 and Playmaker 1.8.8.f2.
I needed to see how far I could push the touch inputs and outputs in real time on some current and slightly older Android devices, so I made a simple project for that.
It contains nothing else but Playmaker, Ecosystem and lately I just added uGUI but the problem I spotted existed before that anyway.
I've built a multi-touch system with FSMs only and it works perfectly. I'm not testing on Unity Remote 5, it's useless. I build apks.
I have FSMs devoted to printing stuff on the screen for testing purposes, in real time, such as coordinates, distances, framerate, etc.
Also I have two UI images (gizmos) that are displayed under the fingers.
They appear when I press the screen and get hidden when I left the finger (phase: ended).
The main problem is that there's a huge lag. Not only as the gizmos trail behind the fingers (when I make circles very fast I can almost catch them up with my fingers!) but also when pressing. It's obvious that the input isn't registered fast enough.
The moves themselves are smooth, I run at near 60 FPS; but really, the gizmos I use don't follow the fingers in true real time, they clearly suffer terrible lag. I'd say, typically 150 - 250 ms, it really shows.
And it's absolutely abysmal for the game I'm making.
I made the scripts as simple as possible. The data of each finger input is checked every frame in its own FSM.
Typically, I have 3 FSMs for each finger:
1. State : manages the flux between the states according to the inputs and their phases.
2. Data : one state FSM that collects touch info in real time.
3. Display : manages the showing/hiding of each gizmo, plus its positionning.
The first FSM is almost an enhanced version of the FSM shown in the official tutorials, save for the fact that the starter state can also trigger a "moved" since I noticed that starting with a swipe can get missed by the "touched" phase.
Regarding the third FSM; I tried several ways to place the gizmo, direct "set property" actions (by dragging the finger game object into the state tab) on the rect transform, fiddled with other positionning actions, but they all have the same problem. The lag remains.
Everything else in the build is meant to be set to low quality. No complex lighting, the project is almost pure vanilla.
I tried to find solutions on internet and it turns out that many developers have had this lag issue too. It also turns out that not many devs seem to make games which require rather tight controls.
The interesting point is that someone I knew coded a simple game for Android, one that needed responsive controls and there never was any kind of lag of that nature. It was pure c#.
Why I think Playmaker MAY be the culprit will be explained below.
https://forum.unity.com/threads/touch-input-lag-other-games-are-fine.239253/https://forum.unity.com/threads/touch-lag-help.483178/https://answers.unity.com/questions/1130946/android-touch-input-lag-1.htmlhttps://forum.unity.com/threads/input-lag-android.372943/They have this problem and the same lag I measured.
No solution was ever provided in those threads.
https://forum.unity.com/threads/how-to-defeat-latency-on-touches.93365/Now that's a more interesting thread.
It ends with a (shameless
link to a plugin (again, another one, *sigh*) that calls the input at a native level, sidestepping Unituh.
https://assetstore.unity.com/packages/tools/input-management/ios-native-touch-107065Good... if you know how to code.
And that's for iOS only.
https://forum.unity.com/threads/unity-ui-dragging-touch-input-feels-pretty-slow-on-android-compared-to-other-games.470536/Unity UI Dragging (touch input) feels pretty slow on Android compared to other games?Now this one is interesting.
User dandepeched posted a video and then also said that:
I've also had performance problems with Touch events on Android. I didn't find any solution on forum so I was thinking about proper way to implement Touch and Mouse.
I do find very good video on this, maybe it can help to someone -
But this does not fix my problem, so I start to analyze what can make such lag. I do found the root cause - external library. I was using "Outline Effect" plugin from Asset store. It was introducing huge lag on Android. After disabling it everything goes really smooth. So you should consider asset store stuff also.
Hope this tips can help someone.
Is there something similar in Playmaker that could be causing the problem?
If it cannot be solved, I literally may have to jump to another engine, a 2D one that already includes visual scripting by default (there are a couple very powerful ones).
Also, right under Scripting Define Symbols in Android Player Player / Configuration, there's a section that's been added around 2017.1 I believe, Active Input Handling although
Looks like this option isn't displayed by default, it's not even documented on Unity's website (
https://docs.unity3d.com/Manual/class-PlayerSettingsAndroid.html), as they literally forgot to explain it.
So I wonder if it's related to the symbols. Here's those I have:
PLAYMAKER;PLAYMAKER_1_8;PLAYMAKER_1_8_8;PLAYMAKER_1_8_OR_NEWER;PLAYMAKER_1_8_5_OR_NEWER;ECOSYSTEM;ECOSYSTEM_0_6;ECOSYSTEM_0_6_OR_NEWER;PLAYMAKER_UTILS
Going back to the idea that there could be a problem with a library or something, could some Playmaker component be the source of the trouble?