Class BaseAction<TPermutation>
Abstract base class for a planner action (counterpart of IOperationalAction).
See also: ActionContext.
Inheritance
Namespace: Unity.AI.Planner.DomainLanguage.TraitBased
Syntax
public abstract class BaseAction<TPermutation> : ComponentSystem, IActionSystem where TPermutation : struct
Type Parameters
| Name | Description |
|---|---|
| TPermutation | Argument permutation type (see generated code or tests for an example) |
Fields
m_ArgumentPermutations
Local storage (cache) for argument permutations generated in GenerateArgumentPermutations(Entity)
Declaration
protected List<TPermutation> m_ArgumentPermutations
Field Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<TPermutation> |
m_ExpansionList
List of states marked for expansion
Declaration
protected EntityQuery m_ExpansionList
Field Value
| Type | Description |
|---|---|
| EntityQuery |
m_FilterTuples
Filtered tuples of entities and indexes in the domain object reference buffer
Declaration
protected (NativeArray<ComponentType>, List<(Entity, int)>)[] m_FilterTuples
Field Value
| Type | Description |
|---|---|
| System.ValueTuple<NativeArray<ComponentType>, System.Collections.Generic.List<System.ValueTuple<Entity, System.Int32>>>[] |
Properties
ActionSystemGuid
Globally unique ID for the action system
Declaration
public Guid ActionSystemGuid { get; }
Property Value
| Type | Description |
|---|---|
| System.Guid |
Name
Name for the action system
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
ApplyEffects(TPermutation, Entity, Entity, Int32)
Apply effects of this action to a copy of the original state using the arguments (i.e. permutation)
Declaration
protected abstract void ApplyEffects(TPermutation permutation, Entity parentPolicyGraphNodeEntity, Entity originalStateEntity, int horizon)
Parameters
| Type | Name | Description |
|---|---|---|
| TPermutation | permutation | Permutation of arguments for this action |
| Entity | parentPolicyGraphNodeEntity | Entity for the policy graph node that is being expanded |
| Entity | originalStateEntity | Entity for the state of the policy graph node that is being expanded |
| System.Int32 | horizon | Horizon of the parent policy graph node |
CopyState(Entity)
Create a copy of the specified state
Declaration
protected Entity CopyState(Entity parentStateEntity)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | parentStateEntity | Entity for the parent state to be copied |
Returns
| Type | Description |
|---|---|
| Entity | Entity for the copied state |
CreateActionNode(Entity)
Create an action node in the policy graph for the expansion
Declaration
protected Entity CreateActionNode(Entity parentPolicyGraphNodeEntity)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | parentPolicyGraphNodeEntity | Entity for the policy graph node that is being expanded |
Returns
| Type | Description |
|---|---|
| Entity | Entity for the newly created action node |
FilterObjects(Entity)
Create tuples of filtered objects based on parameters specified in the Plan Definition
Declaration
protected void FilterObjects(Entity stateEntity)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | stateEntity |
GenerateArgumentPermutations(Entity)
Method for generating argument permutations (that match preconditions) in order to apply effects later
Declaration
protected abstract void GenerateArgumentPermutations(Entity stateEntity)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | stateEntity | Entity for the state of the policy graph node that is being expanded |
GetEntity(DynamicBuffer<DomainObjectReference>, Int32, Entity)
Get the entity at specified index of the state
Declaration
protected Entity GetEntity(DynamicBuffer<DomainObjectReference> domainObjectBuffer, int index, Entity stateEntity)
Parameters
| Type | Name | Description |
|---|---|---|
| DynamicBuffer<DomainObjectReference> | domainObjectBuffer | State buffer of domain object references |
| System.Int32 | index | Index of domain object in buffer |
| Entity | stateEntity | Entity for the state |
Returns
| Type | Description |
|---|---|
| Entity | Entity for the specified domain object |
GetEntityByDomainObjectID(DomainObjectID, Entity)
Look up the domain object entity by DomainObjectID
Declaration
public Entity GetEntityByDomainObjectID(DomainObjectID id, Entity stateEntity)
Parameters
| Type | Name | Description |
|---|---|---|
| DomainObjectID | id | ID of the domain object |
| Entity | stateEntity | Entity for the state |
Returns
| Type | Description |
|---|---|
| Entity | Entity that matches the DomainObjectID |
GetTrait<T>(Entity)
Return the trait for a specified domain object entity
Declaration
public T GetTrait<T>(Entity entity)
where T : struct, IComponentData
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | entity | Entity for the domain object |
Returns
| Type | Description |
|---|---|
| T | The specified trait data |
Type Parameters
| Name | Description |
|---|---|
| T | Trait type |
GetTrait<T>(Entity, Entity, Int32)
Return the trait for a specific argument (i.e. Entity) that was specified with the action
Declaration
public T GetTrait<T>(Entity actionEntity, Entity stateEntity, int argumentIndex)
where T : struct, IComponentData
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | actionEntity | Entity for the planner action node |
| Entity | stateEntity | Entity for the state in which the action is performed |
| System.Int32 | argumentIndex | Index of the argument (corresponds with the parameter index in the Plan Definition) |
Returns
| Type | Description |
|---|---|
| T | The specified trait data |
Type Parameters
| Name | Description |
|---|---|
| T | Trait type |
OnCreateManager()
Declaration
protected override void OnCreateManager()
OnUpdate()
Process:
Input - Entities for policy graph nodes (state) to be expanded
- Iterate over various combinations of parameters by evaluating preconditions
- For every valid combination apply effects (must copy state in the process)
Output - Resulting states + action node information
Declaration
protected override void OnUpdate()
SetActionData(Entity, Entity, Entity, Int32, Entity, Single, Single)
Update the newly created state with additional action information
Declaration
protected void SetActionData(Entity stateCopyEntity, Entity parentStateEntity, Entity parentPolicyGraphNode, int horizon, Entity actionNodeEntity, float value, float probability = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | stateCopyEntity | Entity for the copied state for this action permutation |
| Entity | parentStateEntity | Entity for the state of the policy graph node that is being expanded |
| Entity | parentPolicyGraphNode | Entity for the policy graph node that is being expanded |
| System.Int32 | horizon | Horizon of the newly created policy graph node |
| Entity | actionNodeEntity | Entity for the action node in the policy graph |
| System.Single | value | Transition utility value for following this action |
| System.Single | probability | Probability of this action occuring |
SetTrait<T>(WriteTrait<T>, Entity)
Write back a trait for a specific domain object entity
Declaration
protected void SetTrait<T>(WriteTrait<T> setter, Entity entity)
where T : struct, ITrait
Parameters
| Type | Name | Description |
|---|---|---|
| WriteTrait<T> | setter | Delegate for modifying trait values (uses ref) |
| Entity | entity | Entity for the domain object |
Type Parameters
| Name | Description |
|---|---|
| T | Trait type |