Detailed explanation on how STUP works

In this more detailed explanation of STUP I will once again be using the flowchart with a more detailed explanation of each step and an example on the right side.

To start off we have to see what the state of the world is and make goals according to the worldstate. One goal will be made for every action the AI can do on every object in the world. To keep it simple I will use goals A, B, C, D, and E. These goals can be anything and will be used as an example on the right.

In blueprints

A-

B-

C-

D-

E-

In c++

Now that we have our goals we will have to score them. Each goal will have a rank(R) for how important it is and a score(S) for how important it is at this given moment.

In blueprints

A- R1, S0

B- R1, S1

C- R10, S2

D- R10, S3

E- R10, S4

In c++

We have all these goals in data form now but we need a way to use them in C++ which is why we turn each goal with its data into an FGoalStruct. The FGoalStruct is there to make it easier to know what data you are using in C++.

In blueprints

A- (R1, S0)

B- (R1, S1)

C- (R10, S2)

D- (R10, S3)

E- (R10, S4)

In c++

The goals are now in a state where the C++ can take over so we send them to C++ to create a plan that can then be executed in blueprints.

In blueprints

In c++

A- (R1, S0)

B- (R1, S1)

C- (R10, S2)

D- (R10, S3)

E- (R10, S4)

We are now on the C++ side of things and in the STUP algorithm, this starts with the first step of Utility. What this step does is remove all the goals that we don't want to or cannot use. Goals like these will have a score of 0 or lower so goal A gets eliminated.

In blueprints

In c++

B- (R1, S1)

C- (R10, S2)

D- (R10, S3)

E- (R10, S4)

To do Utility step 2 we first check which goal has the highest rank and then we eliminate every goal with a lower rank. Since goal B's rank 1 is one while the highest rank is 10 it gets eliminated.

In blueprints

In c++

C- (R10, S2)

D- (R10, S3)

E- (R10, S4)

The goals we currently have are relevant so we will make a plan(P) for each of them which will be done using GOAP. During GOAP we will see what the cost(C) of a plan is which is based on the cost of the actions the AI needs to do to complete the goal. If a plan could not be made for any of the goals for whatever reason they will be eliminated. If after GOAP there are no goals left it will return a goal it can always do like "Idle".  

In blueprints

In c++

C- (R10, S2, C2, P)

D- (R10, S3, C0.25, P)

E- (R10, S4, C0.3, P)

Now we have a pretty complicated step that being Utility step 3. What it does is eliminate goals based on a cutoff ratio but if the goals that would be removed are still relevant they will be kept. This is very complicated and is explained in the in-depth explanation but it will have no change on the current goals.

In blueprints

In c++

C- (R10, S2, C2, P)

D- (R10, S3, C0.25, P)

E- (R10, S4, C0.3, P)

As the final step in GOAP we will pick a random goal using the score per cost as weight. With this C will have the lowest chance to be chosen while E has the highest. Because it is random let's say that D gets chosen.

In blueprints

In c++

D- (R10, S3, C0.25, P)

We now have a plan that will be returned to the blueprint so it can be used by the AI.

In blueprints

In c++

D- (P)

The AI now has a vector with actions it can now do and once it has finished or gets interrupted this it will do this process all over again. 

In blueprints

D- P

In c++