Comment on page
Conditions & Effects
Conditions are essentially the prerequisites or requirements that need to be met for an action to be executed. They are tied to the game's state, represented by
- Key: This is the
WorldKeythat the condition checks. Think of it as a variable or a state in the game world, like "PlayerHealth" or "HasAmmo."
- Comparison: This is how the
WorldKeyis compared to a specific value to determine if the condition is met. The available comparisons are "SmallerThan," "SmallerThanOrEqual," "GreaterThan," and "GreaterThanOrEqual."
- Value: This is the specific value that the
WorldKeyis compared against using the specified comparison.
For example, a condition might be set up like this:
- Key: PlayerHealth
- Comparison: GreaterThan
- Value: 50
This condition checks if the player's health is greater than 50.
Effects describe the changes that an action brings about in the game's state, again represented by
- Key: This is the
WorldKeythat the effect modifies. For instance, "PlayerHealth" or "AmmoCount."
- Type: This indicates whether the
WorldKeyvalue will increase or decrease as a result of the action.
For instance, an effect might be:
- Key: AmmoCount
- Type: Decrease
This effect would decrease the ammo count when the action is executed.
The system matches conditions and effects to determine the sequence of actions that lead to a goal. Here's how the matching works based on the provided documentation:
- SmallerThan and SmallerThanOrEqual comparisons in conditions look for actions with negative effects. This means if a condition requires a
WorldKeyto be less than a certain value, the system will look for actions that decrease that
- GreaterThan and GreaterThanOrEqual comparisons in conditions look for actions with positive effects. So, if a condition requires a
WorldKeyto be greater than a certain value, the system will search for actions that increase that
For example, if there's a condition that checks if "AmmoCount" is
SmallerThan5, the system might look for an action with a negative effect on "AmmoCount" (like "ShootBullet"). Conversely, if the condition checks if "AmmoCount" is
GreaterThan10, the system might look for an action with a positive effect on "AmmoCount" (like "ReloadGun").
In essence, the GOAP system uses these conditions and effects to build a graph of possible actions and sequences, which is then used by the planner to determine the best course of action to achieve a goal.
Setting conditions and effects through code.
var builder = new GoapSetBuilder("GettingStartedSet");
Setting conditions and effects through the inspector.