Good day!
Recently I decided to use something like update manager, which puts all “custom updates” in one Unity update. So, the performance of this was really great, scene, which gave around 100 fps presented 500-700 (large fluctuations). It seems that everything should be really nice, but how surprised I was when on android I’ve got troubles with performance. Surely, I increased fps to 60 (because it’s 30 for phones by default), but anyway in profiler I’ve got huge spikes (5-10 fps). But it’s not all, I had some spawn logic which based on time. And I used deltaTime to make this logic the same for all the platforms. It looks like
private float spawnRate = 3f; // how quickly we want spawn objects
private float timeSinceLastSpawn = 0.0f;
public override void UpdateMe()
{
timeSinceLastSpawn += Time.deltaTime;
if (timeSinceLastSpawn >= spawnRate)
{
timeSinceLastSpawn = 0f;
// some logic to spawn object
}
}
And what do you think? Everything great in editor, everything great with build for Windows and WebGL build. But objects wasn’t spawned every spawnRate time on Android devices! They spawned really randomly (the distance between them are random). And the only why it could be is different Time.deltaTime! But when I changed UpdateMe on Unity Update the problem was gone.
Despite the assertion that Unity scripts works on one thread I think that after compiling for android device (at least for android, sadly I can’t check how it would work on IOS) there are some optimization like executing every MonoBehaviour in own thread (because mobile devices, unlike computers, have a large number of cores with a low frequency). If it is so it means that it’s much better to have many small updates instead one large, even despite on every update has a lot of additional actions what are bad for performance.
So what do you think about it?