Game sometimes freezes for half a second on collision

I have some weird behavior on iOS where on collisions the game sometimes freezes for a bit and then resumes. This behavior is quite random and it only happens sometimes but frequently enough (every 5-10 collisions). The weird thing is that on Android this doesn’t happen and it seems that only on iOS there’s a problem. I tried on both an old iPad3 and a new iPhone 5S but it happens on both so CPU power is not the issue here.
In XCode the framerate doesn’t drop and it stays at 30 FPS constantly (also during such game freezes) and the memory is ok so I can’t see what the problem is. It doesn’t happen all the time (and the code run on collision with objects is always the same in the game) and it only happens on iOS devices.

Any idea what the problem can be? Thanks.

Have you used the Profiler to find what is taking more time?

Yes I checked but I have a hard time stopping the profiler at the moment the game freezes (because again, this doesn’t happen in the editor or Android, only on iPhone). I have some spikes here and there during gameplay but the game usually runs fine at 30fps. Then when the freeze happens I don’t really know how to notice if one of those spikes happened exactly at the moment of the freeze or if they are the usual ones.

Few tips, which might help to get to the bottom of this:

  • you can change your target framerate to 60 to notice any spikes easier
  • deactivate Record just after spike happens for profiler not to record any new data
  • analyze what does cause those usual spikes, is it physics? selecting function in profiler will mark it to be more distinguishable

The spikes happen for different reasons, sometimes it’s NGUI UIStretch update function, sometimes is RenderTexture.SetActive, sometimes ParticleSystem.WaitForUpdateThreads…

Is it really possible to get rid of ALL spikes or is it normal to have some once in a while? Currently the FPS and the memory are stable, but it’s just those freezes on iOS that are weird…

Mainly it depends on your game, but some spikes will always be present due to more stuff happening in some frames than others, but those freezes are definitely not expected.

If you manage to get reliable repro of that freeze - please report and post case # here and we will investigate it.

ok I will do that. One thing I always wanted to ask: if I send the project with the bug report tool is confidentiality about the project guaranteed? It’s a project for a client so I need to know that there’s a guarantee that it stays confidential. Thanks!

Yes, of course. You can also strip any art or other assets not required for the repro of the problem.

ok I did submit the bug: 621662

Thanks! :wink:

So just in case someone else has a similar problem - in this case it was Font.CacheFontForText.
Answer how to deal with that is already provided here

mmm, how come it was only happening on collisions and not randomly?

Anyway, I read the solution but I didn’t quite understand how to implement it, so I need to create a render texture with my font texture data on it? Thanks!

That’s the only time you are updating your dynamic font (score).

You can either make your fonts static or if you really need dynamic fonts - render them beforehand, so that cache is big enough not to be increased in runtime. As you don’t want it to be visible you need to render it somewhere that won’t be displayed.

1 Like

Sir my project is just having this issue.
fontcachetotext
it was a score text showing in the game, and updates only when player gets a point.
But it freezes the game so bad at that moment.
You said render them beforehand, I tried to put a text out of screen, renders 0-9. but it seemed like nothing had changed.
Could you give me some directions on how to you cache font before head?

Dylan, you could create your own skin and make a custom GUI style, and then use the script to change the font relative to screen size.