One of my recent biggest challenge is implementing AI in ECS.
So I’ve tried to implement GOAP in ECS. But there were some problems that I cannot solve.
Which is GOAP represent a world state in key/value dictionary.
Entity’s own knowledge to an world state is a Memory, and it also holds partial world states info as Dictionary.
But I don’t know how to implement dictionary type inside component.
I’ll lay down my implementation so far.
===========================
Components
-GOAPActorComponent:IComponentData
bool shouldPlan
int runningActionIdx
-GOAPActionComponent:IBufferElementData
GOAPActionType type
GOAPState preconditions
GOAPState effects
-GOAPGoalComponent:IBufferElementData
GOAPState goals
-GOAPQueuedActionComponent:IBufferElementData
GOAPActionType type
GOAPState settings
-GOAPMemoryComponent:IComponentData
GOAPState worldState
Systems
-GOAPPlanningSystem
=>Plan actions with GoalComponent and ActionComponent inside buffer and put all actions in QueuedActionComponent in ordered
-GOAPPlanExecutionSystem
=>Pull one action and attach corresponding action component to entity.
ex)If QueuedActionComponent.type = GOAPActionType.MoveToPos then attach AIMoveToPos Component
-AIMoveToPosSystem
=>Process AI which AIMoveToPos is attached
GOAPActionType(enum)
-Idle
-MoveToPos
-SaySomething
GOAPState(struct) <=Problem(1) kinda dictionary thingy struct.
-Parameter0
-Parameter1
-Parameter2
-Parameter3
.
.
-Parameter20?
-this[int index] property (to use it as a array)
Parameter(struct) <=Problem(2)
-int key
-int intVal
-bool boolVal
-float floatVal
-float3 float3Val
Actually this implementation looks very not a good way to ECS I know, but it works what i’ve expected.
But there is a limitation,
which GOAPState has fixed fake array type of component, if Memory has some big amount of world state, then this will exceed the size of the struct,
and also other Entity that holds Memory component that hold no states, will have an empty big fixed GOAPState, which is no good.
So far I tried to find other solutions but now I can’t think of any.
Is there a way to avoid this kinda situation?
And if there ain’t, then is there a good way to implement AI in ECS?
I wan’t to know how other people deals AI in ECS.