For our game we decided to use GOAP to make the AI, but most systems didn’t fully comply with our needs so I decided to make our own. The GOAP can be seen in action here.
The game is a fast paced brawler and it’s decision making had to be realtime, unlike the other GOAP systems I found which seemed to be optimized for making decisions every once in a while.
It’s multi-threaded and includes a visualizer to easily see what’s going on.
I suspect the issue is that most people here are individuals or small teams who already wear too many hats and are looking for drop-in AI that exhibits the behavior they need straight out of the box. I see that the github has a couple issues reported, so at least some people are using this generous open source gift to the community.
Thanks for sharing all your hard work with the community. I’ve been wanting to experiment with GOAP in a fast paced prototype of my own, so this will probably come in very handy. Thanks!
Just out of curiosity, does anyone think the new playables API could be used to create a similar system? It would seem like a perfect fit to me, but I don’t know enough about GOAP and playables to be certain.
Oh and perhaps this thread would have been more successful in the Scripting forum? I also don’t know why we don’t have a dedicated AI forum. They should really turn Navigation into that, or make it a sub-forum of AI.
Does anyone use this? I see that the test doesn’t have implemented actions, just a skeleton so I wonder how actions are implemented, and how to keep the precondition stuff unity API free so as to keep it ninja thread friendly.
Also how is movement implemented? In other goap, move is a precondition of proximity and handled by the core GOAP thing.
I haven’t had time to take a look at the playables API but looking at the picture I think something like that would achieve the opposite of what problem GOAP tries to solve; with GOAP you let the system generate the action graph, instead of creating it yourself.
Unfortunately I’m not aware of any game that actually uses this, other than my own game. I would love the hear if anyone uses it!
I really should create a better scene, if you have any small game idea that I could quickly prototype with this please let me know!
The functions used here are all thread save, the result of the preconditions are cached for use during calculations.
A GoapAction has a requiredRange variable that’s being used to find the best action and the Perform() method will only be called if it’s in that range, otherwise it will call the Move() method/callback on the agent until it’s within that range
So you use GOAP for a smasher, that’s interesting I’ve only seen utility AI or BT for that sort of games, what type of action chain do you see created by the planner?
Oh great, GOAP is well suited for building games like Banished so the classical test for that is a logger, a sword smith and a miner. The logger needs an axe to cut trees, the miner needs a pick axe to mine meal, the smith needs wood and metal to forge pick axe and axe.
Fantastic, it helps a lot! Add the methods in that graph for quick lookup
What is “clone” in your sword action?
When you make your game, how do you unit test all that to ensure the actions are using thread safe stuff?
Where is the a* that finds the best chain of action?
That’s actually why I thought playables might be super useful here. From the Unity Manual:
Advantages of using the Playables API
The Playables API allows users to dynamically create blending graphs and control the blending weights directly frame by frame.
A PlayableGraph can be created at runtime, adding playable node as needed, based on conditions. Instead of having a huge “one-size-fit-all” graph where nodes are enabled and disabled, the PlayableGraph can be tailored to fit the requirements of the current situation.
However, I also haven’t had much time to study the API yet. So still not sure if it’s actually suitable for something like GOAP.
Yeah, that’s exactly how I’ve seen other GOAP systems demo it, and it works pretty well. The Unity Labs Behavioral AI Research talk also has a nice demo which I love because it basically models the behavior of a game developer (work, eat, sleep).
It’s weird they’d use GOAP for that sort of Sims behaviour, it’s usually handled far more simply by utility AI. GOAP is good for stuff that need planning, reacting to needs is reactive.
I was anticipating that we needed more actions that what we actually had to use in the end, the example of the visualizer is actually a screenshot of everything we needed for the basic AI. In the end even these couple of actions where more then enough in combination with GOAP to create strong and engaging AI for our particular game. However, certain levels did require some one or two extra actions to be able to handle certain gameplay element, which is where I was extremely happy I choose to use GOAP. Just drop in a couple extra actions on the fly and the system will do it’s magic.
Good idea, I’ll see if I can find some time to make a simple version of this with the GOAP as a proper example scene.
Great idea!
The GoapAgent has a pool of possible actions that are used to generate the tree. When the GoapAgent generates the action tree for each GoapGoal it will clone that GoapAction with it’s settings for actual usage.
Tbh I didn’t, we never got taught any of that during our education. Luckily remembering the difference between what’s thread save and what’s not is quite easy with unity. Unity will also bestow a great deal of errors on you when you do mix it up. Anyway, in general the functions that are/should be used when customizing a GoapAction should all be thread save.
It does sound interesting, gonna take a look at it when I find some time.
Yeah when I was testing GOAP I really liked that part. I’m BT-ing at the moment… to program and zero surprise.
How do you encode game state? In a game with only 5 characters GOAP doesn’t need clever partitioning I suppose, with 1K unit it was having a bit of trouble, firing up all these distance checks.
It’s just a demonstration, but I don’t think there’s anything weird about using it that way either, and I’ve seen others do sims like behaviors with GOAP too. There’s no real right or wrong way to do these sorts of things. Some may be simpler yes, but there’s always trade-offs and the “best” choice is somewhat subjective. Also, how is that kind of simulation any different from say a logger or sword smith?
You do need to keep performance in mind when using GOAP, and there are a number of ways to optimize it, but it really deepens on your type of game. This system was also obviously designed for small scale scenarios with a focus on speed of actions, and was not optimized for large scale simulation. So keep that in mind.
There’s also some talk about GOAP optimization in the GDC video below. It’s also the most hilariously awkward talk I’ve ever seen. My favorite part is when someone asks a question and the french guy points to himself and says “Me?” Love those guys.
I don’t really encode it, it does however perform best if most data is cached/stored in a DataSet. I have in no way designed/tested it for use in 1k agents, if you have any ideas or would like to create a pull request I’d be happy to work on it with you.
It has indeed been designed for per-frame decision making, but if some adjustments would improve performance in other cases as well I’d be happy to make some adjustments!
You mean number of times per second perhaps? I guess I could move the contents of FixedUpdate() to a Tick() function, one could then easily overwrite FixedUpdate() to remove the Tick() call and call Tick themselves?
You can do as you like, on Update() you can call tick with time interval you want , it can be frames per second or some millisecond.
Some heavy process don’t need to be called each frame, for example low level functionality like detection process, raycast etc …It’s a common way to avoid calling process each frame when it is not really needed to get better performance.
Very cool. I haven’t done anything with it yet because I learn by example, as soon as you put something I can see moving, even simple, I’m sure I’ll be able to get started.