PlayMaker Help & Tips > Android Help
Touch input lag
Broken Stylus:
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.html
https://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-107065
Good... 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:
--- Quote ---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 -
//www.youtube.com/watch?v=SrCUO46jcxk
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.
--- End quote ---
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?
djaydino:
Hi,
These symbols are there to check if you have playmaker installed (same for the Ecosystem) the should not have anything to do with performance.
I think the issue is a unity issue and the playmaker touch actions uses the standard (unity) coding.
But i can't really confirm if its laggy as i use 3rd party assets for touch a looong time already and never used the standard (unity)
Also keep in mind that the devices touch always have some lag ( you can test this on the device, somewhere in the developer options you can set 'Show touches')
Can you show a video on how much lag it is and maybe pm me a link to your project so i could test (with pm actions/in C#/3rd party asset) ?
jeanfabre:
Hi,
PlayMaker has nothing to do with touch input lags, you should very careful monitor your game on the device using the unity profiler, and check the framerate and especially what happens whenb the user touches the screen, it may be responding fine but what you want Unity to do is taking time and this is the lga you witness.
so to test this, make a totally simple button or cube with a touch trigger that change color of the background randomly or something, and see how fast it reacts, than compare this with your game with all your features, gameplay, etc etc, if there is a difference, it's your game logic or graphics or sounds that are responsible.
Bye,
Jean
Broken Stylus:
Hello,
Yes, the actions use the touch.input etc. There shouldn't be any problem.
The native option for showing touches on an Android device did indeed reveal a slight lag on the phone's side, but it was acceptable.
This latency is not the one found in Unity.
It looks like this "natural" latency gets multiplied by Unity.
I'll not integrate my touch system into the game yet if I can't even have it work properly in a test project.
It's weird because it's absolutely smooth, the frame rate is totally ok and every single input I generate by touching the screen (touch or swipe) is properly memorized. There's no loss of data.
It's just that all the stuff data arrives many frames later.
If there was a performance bottleneck of some kind, the frame rate would simply fall to its knees as long as I'd be touching the screen. Such is not the case.
Also, I have a rotating cube that does change colour. It works but the latency is present too: the colour is changed with a noticeable delay which just happens to be that of the latency itself.
Clearly, any Unity code that uses any input's info/data gets treated with a considerable delay and yet the FPS are high.
Every single input is kind of affected by an "input saved! see you x frames later" "please hold the line" phenomenon.
I'll run those tests, if the profiler is nice and spots my android device (does not always work).
On a sidenote, this time I got a warning during the building process, which I aborted:
--- Quote ---Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices.
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
--- End quote ---
I was allowing the cube's colour to be modified with a mouse click. Been removed but the problem remains.
Additionally, I had noticed having few but regular global illumination spikes in the profiler (around 15-20 ms) despite having low quality settings, no calculations, shadows, no light, no nothing. :)
Crazy stuff.
Broken Stylus:
Just curious but do I need to pay for Unity Plus in order to be able to use the Profiler with the apk running on the smartphone?
Navigation
[0] Message Index
[#] Next page
Go to full version