I’m looking int implementing utility theory in my BT but I struggle with some of the concepts.
I find it difficult to wrap my head around how to properly define the utilities to use in my BT and to abstract out these concepts in my implementation.
I’m building a space 4x game and I use behavior trees for my AI. In order to make decisions on what branch of the BT, I’m using utility functions on the selector.
For example, I have a construction ship that can build different space stations (space port, defense station, trade post,…). These stations are dynamic. They are also defined as scriptable objects in Unity. The ship itself has a list of these station SOs so I know what he can build.
Because of this dynamic behavior, I fail to find a good way to abstract out the utility from these buildings.
My construction ship has a BT where one of the actions should be “build station” but I can’t find a good way to define how he decides what building to choose…
I can’t create a leave branch per station type as I don’t know up front what stations I can build and with new tech being research, additional stations will become available.
So I’m looking at some general advice on how to properly define these utilities functions…
How’s that even possible?
YOur AI absolutely should have a way to verify if it can build a station type X.
And failing that you can simply create “build most suitable type of station” node for your behavior tree. The stations have some sort of stats, yes? That allows you to whip up some sort of heuristic for deciding which one you want based on stats.
Do keep in mind that you do not need to implement every single part of AI in behavior trees only, and the trees are supposed to be high level concepts. So when the problem becomes fragmented into many small pieces, you should probably take all those pieces and implement them in code, as a new node in behavior trees.
One way I have always done, is to have a separate Utility tree trigger concepts in a blackboard, and have the BT act on these concept by simply reading/testing them in evaluation nodes. Basically separate sensing and acting.