Search Unity

Preventing spikes by Font caching

Discussion in 'Immediate Mode GUI (IMGUI)' started by laurentlavigne, Jun 19, 2016.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,365
    I noticed that on first ongui text display the profiler spikes, font caching seems to be involved.
    Shader have PreWarm() to avoid stuff like that, what's the Font equivalent?
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    OnGui is only used for the editor and legacy products, so there shouldn't be a reason to try and optimize it. But as far as what you're asking, I don't think there's an equivalent, but if for some very specific reason you need trickery to achieve caching, you can enable the component for a single frame at the beginning and turn it off right after. Usually you don't see the visuals, and if it's a problem, put a black image on top of it. I used this technique to cache all spine animation objects in my scene at the start, because they were causing lag spikes when they started their first animation.