System UnrealPlugin InferenceInterfaces Component - kcccr123/ue-reinforcement-learning GitHub Wiki

Inference Actor Component

UInferenceModelActorComponents is a UActorComponent subclass designed to run inference on a per-frame basis within an Unreal Actor. It allows developers to attach trained model logic directly to gameplay actors, enabling autonomous behavior via ML policies.

This component is built to work with any implementation of UInferenceInterface.


Overview

The component exposes a standardized inference loop in the form of TickComponent. Each frame, it generates a state string, runs the model, receives an action, and applies that action to the actor.

This allows actors to behave autonomously without relying on bridge-based training logic, and is ideal for putting trained and exported policies to use.


Usage

  1. Add the component to any actor
  2. Set the inference interface with SetInferenceInterface()
  3. Call StartInference() to enable ticking

Key Methods

void StartInference()

Enables TickComponent, which begins the inference loop. Should be called after a model has been loaded and set.

void StopInference()

Disables ticking and halts inference evaluation.

bool SetInferenceInterface(UInferenceInterface* Interface)

Assigns the backend model interface (e.g., ONNX). Returns true if valid.

FString RunLocalModelInference(const FString& Observation)

Invokes RunInference on the current interface using a formatted state string.


Required Overrides

The following virtual methods must be implemented for the component to perform useful logic:

FString CreateStateString()

Construct a serialized representation of the actor's current state.

EXPECTED FORMAT:

"<obs_0>,<obs_1>,...,<obs_n>"

Used as input to the model.

void HandleResponseActions(const FString& actions)

Decode the returned model output and apply it to the actor (e.g., set velocity, trigger animation).

bool IsActionRunning()

Return true if the current action is still executing. Used to avoid spamming inference while actions are still playing out.


TickComponent()

Internally handles the full inference loop each frame:

  1. If no action is currently running
  2. Serialize state using CreateStateString()
  3. Run model with RunLocalModelInference()
  4. Apply result using HandleResponseActions()
  5. Set bIsWaitingForAction to true until IsActionRunning() returns false
⚠️ **GitHub.com Fallback** ⚠️