跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
数据与分析

ue-async-threading

Use when offloading work off the game thread, dispatching results back to it, running data-parallel loops, or scheduling timers and tickers in UE C++. Also use when the user mentions 'UE::Tasks::Launch', 'FPipe', 'FTaskEvent', 'AsyncTask', 'Async()', 'TFuture', 'TPromise', 'ParallelFor', 'FRunnable', 'FAsyncTask', 'FCriticalSection', 'FRWLock', 'UE::FMutex', 'TMpscQueue', 'IsInGameThread', 'FTSTicker', 'SetTimer', 'thread safety'. For async asset loading, see ue-data-assets-tables; for smart pointers and GC lifetime, see ue-cpp-foundations.

quodsoler · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add quodsoler/unreal-engine-skills --skill ue-async-threading

技能说明


name: ue-async-threading description: "Use when offloading work off the game thread, dispatching results back to it, running data-parallel loops, or scheduling timers and tickers in UE C++. Also use when the user mentions 'UE::Tasks::Launch', 'FPipe', 'FTaskEvent', 'AsyncTask', 'Async()', 'TFuture', 'TPromise', 'ParallelFor', 'FRunnable', 'FAsyncTask', 'FCriticalSection', 'FRWLock', 'UE::FMutex', 'TMpscQueue', 'IsInGameThread', 'FTSTicker', 'SetTimer', 'thread safety'. For async asset loading, see ue-data-assets-tables; for smart pointers and GC lifetime, see ue-cpp-foundations." metadata: version: "2.0.0" engine: "5.8"

UE Async and Threading

Target engine: UE 5.8. APIs below are verified against the 5.8 headers; older forms are listed under "Deprecated — do not use".

This skill covers moving work off the game thread and bringing results back: the UE::Tasks system (Tasks/Task.h, Tasks/Pipe.h), Async/TFuture (Async/Async.h, Async/Future.h), thread-pool FAsyncTask (Async/AsyncWork.h), ParallelFor, dedicated FRunnable threads, locks and lock-free queues, FTSTicker and FTimerManager. Everything except timers is in the Core module; FTimerManager is in Engine; ENQUEUE_RENDER_COMMAND is in RenderCore. Build.cs: PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine" }); and add "RenderCore" only when enqueuing render commands.

Context

Read .agents/ue-project-context.md if it exists (module names, conventions, enabled plugins, GAS/networking setup). Do not stop if it is missing.

Identify the area from the request and the codebase. Ask only when two plausible readings would produce different code.

Request is about…Go to
Which API fitsPattern Selection
One-shot background work, chaining, prerequisites, eventsUE::Tasks
Serializing access to a resource without a dedicated threadFPipe and FTaskConcurrencyLimiter
Futures, promises, dispatch to the game threadAsync, TFuture and AsyncTask
Reusable pooled work unitFAsyncTask and FAutoDeleteAsyncTask
Data-parallel loopsParallelFor
Long-lived dedicated threadFRunnable and FRunnableThread
Locks, events, atomics, queues, shared pointersSynchronization
Per-frame callbacks and delayed callsTickers and Timers
UObject, GC and render-thread rulesThread Safety Rules
Old formsDeprecated — do not use

Threading Model

ThreadCheckOwns
Game threadIsInGameThread() (CoreGlobals.h)All UObject access, Blueprint, gameplay, timers, tickers
Render threadIsInRenderingThread()Scene proxies, render commands (ENQUEUE_RENDER_COMMAND)
RHI threadIsInRHIThread()GPU command submission
Worker threadsnoneUE::Tasks scheduler, TaskGraph AnyThread, ParallelFor
Thread poolsnoneGThreadPool, GBackgroundPriorityThreadPool, GIOThreadPool; GLargeThreadPool only WITH_EDITOR (Misc/QueuedThreadPool.h)

Golden rule: UObjects are game-thread-only. Compute off-thread on plain data, then apply results on the game thread through a TWeakObjectPtr (see Thread Safety Rules).

Pattern Selection

NeedUseResult
One-shot background work, dependencies, chainingUE::Tasks::LaunchTTask<T>
Run a lambda on the game thread from anywhereAsyncTask(ENamedThreads::GameThread, ...)none
Future-style result with execution-context choiceAsync(EAsyncExecution, ...)TFuture<T>
Serialize tasks touching one resource (FIFO)UE::Tasks::FPipeTTask<T>
Cap how many tasks run at onceUE::Tasks::FTaskConcurrencyLimiternone
Reusable pooled work unit with owner-managed lifetimeFAsyncTask<T> / FAutoDeleteAsyncTask<T>via GetTask()
Data-parallel loop, caller blocksParallelFornone
Long-lived thread (socket, file watcher, sim loop)FRunnable + FRunnableThread::Createmanual
Per-frame callback outside an Actor tickFTSTicker::GetCoreTicker().AddTickerhandle
Delayed or repeating call on the game threadFTimerManager::SetTimerFTimerHandle

UE::Tasks

#include "Tasks/Task.h"
// Tasks/Task.h:299
template<typename TaskBodyType>
UE::Tasks::TTask<TInvokeResult_T<TaskBodyType>> Launch(const TCHAR* DebugName, TaskBodyType&& TaskBody,
    ETaskPriority Priority = ETaskPriority::Normal,
    EExtendedTaskPriority ExtendedPriority = EExtendedTaskPriority::None,
    ETaskFlags Flags = ETaskFlags::None);
// Tasks/Task.h:324 — same, with a prerequisites collection as the third parameter
template<typename TaskBodyType, typename PrerequisitesCollectionType>
UE::Tasks::TTask<TInvokeResult_T<TaskBodyType>> Launch(const TCHAR* DebugName, TaskBodyType&& TaskBody,
    PrerequisitesCollectionType&& Prerequisites,
    ETaskPriority Priority = ETaskPriority::Normal,
    EExtendedTaskPriority ExtendedPriority = EExtendedTaskPriority::None,
    ETaskFlags Flags = ETaskFlags::None);
using namespace UE::Tasks;

TArray<int32> Data;
TTask<int32> Sum = Launch(UE_SOURCE_LOCATION, [Data]() { return ComputeSum(Data); });

// Prerequisites: TaskB runs after TaskA completes. Handles are copyable; GetResult() is non-const.
TTask<FVector> TaskA = Launch(UE_SOURCE_LOCATION, []() { return FVector(1.f, 2.f, 3.f); });
TTask<void> TaskB = Launch(UE_SOURCE_LOCATION,
    [TaskA]() mutable { const FVector Pos = TaskA.GetResult(); ConsumePosition(Pos); },
    Prerequisites(TaskA), ETaskPriority::BackgroundNormal);

// Manual gate: nothing after the event starts until Trigger()
FTaskEvent Gate{ UE_SOURCE_LOCATION };
TTa
阅读完整来源 ↗