I’m currently working on porting our iphone games (chop chop series) to android. I’m almost done we all of them, but I just notice something very annoying which was obvious in our sports game, but was crystal clear in our “runner” game. There seems to be about ~0.5-1.0 sec input and sound lag in the game. This completely kills the “runner” game’s gameplay since it relies on fast paced single touch input.
Am I the only one having similar issues? Is there anything to do about them?
Apart from that, everything is going really smoothly, thanks for the great job unity
There should not be any lags. Can you reproduce them in a small basic scene?
Otherwise you way want to profile your game or may be check scripts, or try on another device.
I don’t have input lag but the sound lag is terrible, in 3.0 and 3.1. Anybody have tips on ways to get the Android to play a sound when you ask it to instead of a half second later?
I’ve already tried it.
Unfortunately it doesn’t solve the problem on android. (As far as I know it’s working on iphone only.)
I couldn’t find the solution yet. (I’ve been searching for a while on the internet.)
All android devices on the market today have at least around 100ms lag on touch input. Unfortunately, the way Android handles touch input through its IPC layers the latency can’t be avoided.
Unless you have input lag above 200ms there is nothing Unity3D can do about it.
Tablet Xperia Z: I can not see any touch input lag, but audio latency is about 300-500ms. Any descibed sollutions (Decompress on Load, Compressed in memory…, wave, mp3… Best latency, Good latency…) doesn’t work at all. Who know the sollution?
Cake is right. The sound latency on most Android devices is times higher than on iOS, and this comes from the hardware, drivers and operating system itself. This latency depends on the particular device model - can be better on for example Galaxy Nexus, and worse on others.
Apart from the settings recommended above, there’s not much space for improvement… With the variety of devices, it’s nearly impossible to guarantee specific latency numbers. Sad but true.
I also have audio latency problems on Android devices.
I have changed DSPBuffer Size to Best Latency (in Unity’s AudioManager settings), I have also tried to set it to default and changed it in code via AudioSettings.SetDSPBufferSize to various value combinations. I have sounds for several percussion instruments (they all have their peaks as soon as possible in the sound wave) which I want to play when I press something. They are all 16 bits .wav files, set to “Load in memory” and 2D. The sound clips are set on individual AudioSources, so I only have to call Play to call them. These sources have all “bypass” effects checkboxes turned on. I would say this is a pretty much perfect setup for sounds to play with minimal delay in Unity. (I have also tried mono, oggs, compressed and not, etc).
Regarding input, I play sounds when a key/mouse/touch is pressed down (not up, as that would result in further lag). I’ve tried it inside of OnGUI and Update, in response to UI Button events, etc. I’ve also used an almost empty scene without extra processing of any kind.
Everything works without lag using a mouse in desktop builds (as expected). But I STILL have latency that is much higher than native applications in my Android device. I can notice a small delay no matter the app, but can hear the sound almost immediately for example in this app: https://play.google.com/store/apps/details?id=br.com.rodrigokolb.realdrum. This delay would be good enough for my use case. In contrast, no matter what I do in Unity, I always hear the sound significantly after the touch. I’ve turned on Android developer settings to show my touch and the touch response of my device is pretty much instant. Unity’s response to touch seems to lag a bit behind, and then the audio adds to that.
We’re almost in 2015 and Unity still provides no way to reduce audio latency to satisfactory levels? This is killing rhythm games on the engine.
What is your method for measuring touch lag and audio lag? What devices are you testing with?
The lag I have isn’t much worse than the expected hardware+OS lag. All mobile devices have a pretty significant amount of touch lag and audio lag and it will be different between devices. If you’re getting lag that is a lot worse than can be expected from hardware, then you’re probably doing something wrong.
I wish I was doing something wrong and could improve the lag. I find that hard to believe, currently. If I compare the lag I get with the Drum application I linked with the lag I get from my test app, they are certainly different.
My test “method” consists simply in tapping the floor at a certain speed (say, 120 bpm) with my foot and press the screen with my finger at the same time. In the Drum application I get the sound from the device almost immediately after my foot’s (I can notice the lag, but it’s the expected amount). With anything I could come up with in Unity, delay is much higher. If I tap at relatively fast speeds I get the sound response from the game almost off-beat (i.e. midway through two finger presses). Actually, 120 bpm is almost fast enough for that to happen, and the sound wave is not the problem, as desktop builds of the game don’t have any lag.
I’ve currently tested on an Samsung Galaxy S3 and a Nexus tablet. I’ve had other people test it on these devices and they could certainly notice the difference in lag. I would give up on this if native Android apps had similar lag, but this is not the case.
It’s certainly either Unity’s problem or my problem using the engine. I’ve tried everything I know, and haven’t read any topic/thread/webpage that could help me, hence why I’m inclined to believe the former case. I would love to be publicly proven wrong, though. It would mean I could solve the problem.
Prior to 2013, there was almost no way to get an acceptable audio latency for a musician in Android.
Then, Google presented High Performance Audio GitHub - gkasten/high-performance-audio: Automatically exported from code.google.com/p/high-performance-audio . You might want to watch Glenn Kasten’s video on YouTube (link available on that page). The bottom line is - for newer devices, there is a way to enable audio fast path, and get a decent latency.
We experimented with OpenSL and fast path in Unity. The latency is improved on some devices comparing to the default Java driver, but some devices show latency regression, and some have glitches. We cannot release it as is, so we are collaborating with Glenn and other folks at Google to get a solution. It will find its way to the release when stable enough.
Addition: Galaxy S3 is not the best audio device out there. Galaxy Nexus is good, not sure about Nexus 7 and 10.
Thanks for the explanation, Yury. So the native app I linked might be using high performance audio, and Unity currently does this differently, having worse lag. Would this be correct?
By creating a custom native Android plugin in Java just to play a sound, and calling it from Unity, would I potentially be able to improve latency? (before your work with OpenSL becomes part of Unity) If so, would this require Unity Pro? It would be my first time trying to create an Android plugin.