Defer Agents

When loading glTFs, glTFast let's you optimize towards one of two diametrical goals

  • A stable frame rate

  • Fastest loading time

By default each GltfAsset instance tries not to block the main thread for longer than a certain time budget and defer the remaining loading process to the next frame / game loop iteration.

If you load many glTF files at once, by default they won't be aware of each other and collectively might block the main game loop for too long.

You can solve this by using a "defer agent". It decides if work should continue right now or at the next game loop iteration. glTFast comes with two defer agents

  • TimeBudgetPerFrameDeferAgent for stable frame rate

  • UninterruptedDeferAgent for fastest, uninterrupted loading

This excerpt is taken from glTFast documentation.

If no defer agent is specified, default defer agent is set to UninterruptedDeferAgent.

To Set A Defer Agent

  1. We provide a prefab for setting the TimeBudgetPerFrameDeferAgent, you can find it in Packages/Ready Player Me Core/Runtime/Core/Resources folder.

  1. This can then be referenced in GLTF defer agent field in settings.

The reason for creating our own wrapper around glTFast defer agent is to provide developers with the option to create their own custom defer agent.

Custom Defer Agent

A custom defer agent can be created by implementing IDeferAgent provided by glTFast. To use it with Ready Player Me, attach a DeferAgent component to the gameObject and reference the gameObject in the settings menu.

public class CustomDeferAgent: MonoBehaviour, IDeferAgent 
{
   public bool ShouldDefer() 
   {
       return false; 
   }
   
   public bool ShouldDefer(float duration)
   {
       return false;
   }

   public Task BreakPoint()
   {
       return null;
   }
   
   public Task BreakPoint(float duration)
   {
       return null;
   }
}

Last updated