unreal.LearningAgentsInteractor

class unreal.LearningAgentsInteractor(outer: Object | None = None, name: Name | str = 'None')

Bases: LearningAgentsManagerComponent

ULearningAgentsInteractor defines how agents interact with the environment through their observations and actions. Additionally, it provides methods to be called during the inference process of those agents.

To use this class, you need to implement the SetupObservations and SetupActions functions (as well as their corresponding SetObservations and SetActions functions), which will define the size of inputs and outputs to your policy. Before you can do inference, you need to call SetupInteractor, which will initialize the underlying data structure, and you need to call AddAgent for each object you want controlled by this agent interactor.

C++ Source:

  • Plugin: LearningAgents

  • Module: LearningAgents

  • File: LearningAgentsInteractor.h

Editor Properties: (see get_editor_property/set_editor_property)

  • action_objects (Array[LearningAgentsAction]): [Read-Only] The list of current action objects.

  • asset_user_data (Array[AssetUserData]): [Read-Write] Array of user data stored with the component

  • auto_activate (bool): [Read-Write] Whether the component is activated at creation or must be explicitly activated.

  • can_ever_affect_navigation (bool): [Read-Write] Whether this component can potentially influence navigation

  • component_tags (Array[Name]): [Read-Write] Array of tags that can be used for grouping and categorizing. Can also be accessed from scripting.

  • editable_when_inherited (bool): [Read-Write] True if this component can be modified when it was inherited from a parent actor class

  • helper_objects (Array[LearningAgentsHelper]): [Read-Only] The list of current helper objects.

  • is_editor_only (bool): [Read-Write] If true, the component will be excluded from non-editor builds

  • is_setup (bool): [Read-Only] True if this component has been setup. Otherwise, false.

  • manager (LearningAgentsManager): [Read-Only] The associated manager this component is attached to.

  • observation_objects (Array[LearningAgentsObservation]): [Read-Only] The list of current observation objects.

  • on_component_activated (ActorComponentActivatedSignature): [Read-Write] Called when the component has been activated, with parameter indicating if it was from a reset

  • on_component_deactivated (ActorComponentDeactivateSignature): [Read-Write] Called when the component has been deactivated

  • primary_component_tick (ActorComponentTickFunction): [Read-Write] Main tick function for the Component

  • replicate_using_registered_sub_object_list (bool): [Read-Write] When true the replication system will only replicate the registered subobjects list When false the replication system will instead call the virtual ReplicateSubObjects() function where the subobjects need to be manually replicated.

  • replicates (bool): [Read-Write] Is this component currently replicating? Should the network code consider it for replication? Owning Actor must be replicating first!

decode_actions() None

Call this function when it is time for your agents to take their actions. You most likely want to call this after your policy’s EvaluatePolicy function to ensure that you are receiving the latest actions. This will call this agent interactor’s GetActions event.

encode_observations() None

Call this function when it is time to gather all the observations for your agents. This can be done each frame or you can consider wiring it up to some kind of meaningful event, e.g. a hypothetical “OnAITurnStarted” if you have a turn-based game. This will call this agent interactor’s SetObservations event.

get_action_vector(agent_id=-1) Array[float]

Gets the action vector used by a given agent. Should be called only after EncodeActions or EvaluatePolicy.

Parameters:

agent_id (int32) – The AgentId to look-up the action vector for

Returns:

out_action_vector (Array[float]): The action vector for the given agent

Return type:

Array[float]

get_actions(agent_ids) None

During this event, you should retrieve the actions and apply them to your agents.

Parameters:

agent_ids (Array[int32]) – The list of agent ids to get actions for. See: LearningAgentsActions.h for the list of available actions. See: GetAgent to get the agent corresponding to each id.

get_observation_vector(agent_id=-1) Array[float]

Gets the observation vector used by a given agent. Should be called only after EncodeObservations.

Parameters:

agent_id (int32) – The AgentId to look-up the observation vector for

Returns:

out_observation_vector (Array[float]): The observation vector for the given agent

Return type:

Array[float]

set_observations(agent_ids) None

During this event, all observations should be set for each agent.

Parameters:

agent_ids (Array[int32]) – The list of agent ids to set observations for. See: LearningAgentsObservations.h for the list of available observations. See: GetAgent to get the agent corresponding to each id.

setup_actions() None

During this event, all actions should be added to this agent interactor. See: LearningAgentsActions.h for the list of available actions.

setup_interactor() None

Initializes this object and runs the setup events for observations and actions.

setup_observations() None

During this event, all observations should be added to this agent interactor. See: LearningAgentsObservations.h for the list of available observations.