BrianPansky Wiki
Advertisement

For coding generative, emergent games, ECS (Entity Component Systems) is all the rage.  For AI with adaptable, emergent behavior, GOAP (Goal Oriented Action Planning) is all the rage.

But when I searched for help implementing GOAP in ECS...I don't find much.  Just one person having difficulty, and someone telling them "well maybe just don't use (pure) ECS then".  [example] Admittedly this second example is from someone who didn't say they were using GOAP, but people still basically say "just break the rules of ECS". [example] Here's a similar one with admittedly mixed responses as well: [example].

So...are they really that incompatible?  Should I use non-ECS for the AI?

I'll try to figure this out.  As of now, I haven't tested any of my ideas here.  I'm not even experienced with using ECS or GOAP on their own. Welp, just 3 or 4 days after I started, seems fine, I don't see any issues. Keep in mind:

  • I've never made any AI before, and I made this one from scratch, just learning the concepts of GOAP from others
  • I've never used ECS before
  • never once in the days of working on it did I feel like there was any problem with the system, it was always pretty easy to figure out what I needed to do next
  • nearly all the time I've spent on it has been trying to get the recursive "plan mapping" algorithm to work
  • I have now (next morning) also made the data state of the AI update when it completes a goal or step in a plan. So that's no difficulty either.

What are ECS and GOAP?

ECS

ECS is pretty simple.  There are entities compesed of components, and that is all just the data.  Then there are "systems" (which leads me to think ECS should actually be ECSS:  Entity Component System Systems) which handle all of the computation, processing, updating the data.

Simple simple (and yet so many people get confused)

What is GOAP?

Well, I'll summarize what I gather from two sources:

GOAP Video by TheHappieCat

Actions have:

-prerequisites

-outcomes

Also, some "weights" are applied to the paths along the means-ends chains/trees etc.

Video dismissed idea of putting the weights in the "outcomes"?

Then find the best "path" to the goal.

Put that path in a "stack" of actions to do...

STRIPS and GOAP from Jeff Orkin paper

Starts with STRIPS.

Again, actions are defined in terms of prerequisites and effects (outcomes).

Also, in example, each character type has these actions, as part of their description.  Their data?

Need a description of the world, to check if prerequisites are met (and maybe other things?).  Often this is mostly (completely?) describing only the stuff the AI character has and wants?

Check which paths are possible.

What if more than one possible path?

He says they used GOAP, which differs from STRIPS in four ways:

1-GOAP has a cost per action

2- (something something)

3 and 4 - GOAP for them added "proceedural preconditions and effects"

And the use A* (A sharp?) to find "paths", means-ends chains, and pick best one.

Can I figure this out?

So, what parts of GOAP is the components, what is the systems?  And what might those components and systems need to look like?

Well, components are just data, so all this stuff:

-state of the world

-what the AI wants

-what the AI can do, actions, and their weights

Systems:

-computing best path (use A*)

-animation

-updating world and all that

Am I missing anything?


Seems like it should be totally fine!  Maybe the people having difficulty, and the people helping them, are just noobs?

Well, maybe could look at specific problems people said they had...

How I might answer problems people said they had

Too many condition checks!?

Someone said they would have to many condition checks to see what actions a character could do.

So, this might depend on whether the list of possible actions needs to be updated generatively.

If you have a static list, it's easy:  the list of possible actions is hard coded into the components, the data.  Then the (means-ends) pathfinding system picks the best path.

Does the pathfinding system need to check tons of conditions?  Maybe not:  remember, the actions themselves specify their prerequisites and outcomes.  So the pathfinding system can generate chains on the fly just by matching strings of descriptive text if you want.  Start from one end of the chain, construct the rest of the chain(s), compare to world state, pick the best chain.

I don't think the "checks" the person had in mind are needed here.

What about more generative AI?  Where their list of possible actions might get updated?  Updating that list seems different from that "action picking" stuff.  So it's not really the issue that person was talking about.  So I'll think this through later/elsewhere I guess.

Advertisement