trophy 0
May 2025 116 posts
Sandbox.GameTask : api/Sandbox.GameTask
trophy 820
May 2023 33 posts
GameTask is a global, engine-owned async helper built on top of TaskSource.
It manages async work for the entire lifetime of the current game session, rather than for a specific object or system within the game.

All GameTask operations are automatically canceled only when the session ends (for example, on a map change or reload).
There is no object-level or manual cancellation.

If your async logic belongs to something that does not live for the entire game session—such as entities, components, abilities, or other in-game systems—you should use TaskSource instead, so the async work is canceled when that object is destroyed. 


For Example:

a Global Logger that:
  • Start when the game starts
  • Not defined by an entity
  • stop when session ends
public static class PerformanceLogger
{
    public static void Start()
    {
        _ = Run();
    }

    static async Task Run()
    {
        while ( true )
        {
            await GameTask.DelaySeconds(1);
            Log.Info($"FPS: {HostStats.Fps}");
        }
    }
}
once called from a session entry point (like a GameObjectSystemusing ISceneStart) the logger will be active and persist without be attached to something within the game.


people
Log in to reply
You can't reply if you're not logged in. That would be crazy.