Skip to content

Commit 1bfdb14

Browse files
authored
Expand docs to explain tick behavior (#396)
1 parent 7d30a8e commit 1bfdb14

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

β€Ždocs/manual/selector.mdβ€Ž

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,50 @@ Type of Node | Child returns `RUNNING`
1414
`SelectorComposite` | Tick again
1515
`SelectorReactiveComposite` | Restart
1616

17+
`Tick again` means that it will (for each consecutive tick) skip previous nodes that already ran and tick **only** the current `RUNNING` node again until it is no longer `RUNNING`.
18+
19+
`Restart` means that it will tick all previous nodes that already ran and then tick the current `RUNNING` node again.
20+
21+
### When to Use Restart vs Tick Again
22+
23+
The choice between "restart" and "tick again" behaviors impacts how your selector responds to dynamic game environments:
24+
25+
#### When to Use "Tick Again" Behavior
26+
Choose a selector with "tick again" behavior (`SelectorComposite`) when you need to:
27+
28+
- **Maintain action continuity**: Ensure long-running tasks complete without interruption
29+
- **Preserve computational resources**: Avoid re-checking conditions that are unlikely to change
30+
- **Create stable, predictable behavior**: When commitment to the current action is more important than responsiveness
31+
32+
**Example**: A character performing a special ability that must complete its full animation sequence before considering other options.
33+
34+
```
35+
SelectorComposite
36+
β”œβ”€ IsSpecialAbilityTriggered (Condition: success)
37+
β”‚ └─ PerformSpecialAbility (Action: running)
38+
β”œβ”€ IsEnemyNearby (Condition: not evaluated while ability is running)
39+
└─ Patrol (Action: not evaluated while ability is running)
40+
```
41+
42+
#### When to Use "Restart" Behavior
43+
Choose a selector with "restart" behavior (`SelectorReactiveComposite`) when you need to:
44+
45+
- **Prioritize responsiveness**: Immediately react to changing high-priority conditions
46+
- **Implement interrupt-driven behavior**: Allow higher-priority tasks to interrupt lower-priority ones
47+
- **Handle volatile environments**: Re-evaluate all options when the game state changes frequently
48+
49+
**Example**: An AI that should immediately respond to threats regardless of current activities.
50+
51+
```
52+
SelectorReactiveComposite
53+
β”œβ”€ IsUnderAttack (Condition: initially failure, later success)
54+
β”‚ └─ DefendSelf (Action: will interrupt ongoing tasks when under attack)
55+
β”œβ”€ IsHungry (Condition: success)
56+
└─ SearchForFood (Action: interrupted when attack detected)
57+
```
58+
59+
The "tick again" approach improves performance and ensures action completion, while "restart" provides greater adaptability to changing conditions at the cost of potentially interrupting ongoing tasks.
60+
1761
## Selector Random
1862
The `SelectorRandomComposite` node behaves similarly to the Selector Star node, but instead of executing its children in the given order, it executes them in a random order.
1963

β€Ždocs/manual/sequence.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,48 @@ Type of Node | Child returns `FAILURE` | Child returns `RUNNING`
1717
`SequenceReactiveComposite` | Restart | Restart
1818
`SequenceStarComposite` | Tick again | Tick again
1919

20+
`Restart` means that it will tick all previous nodes that already ran and then tick the current `RUNNING` node again.
21+
22+
`Tick again` means that it will (for each consecutive tick) skip previous nodes that already ran and tick **only** the current `RUNNING` node again until it is no longer `RUNNING`.
23+
24+
### When to Use Restart vs Tick Again
25+
26+
The choice between "restart" and "tick again" behaviors has significant impacts on your sequence's effectiveness in different scenarios:
27+
28+
#### When to Use "Restart" Behavior
29+
Choose a sequence with "restart" behavior when you need to:
30+
31+
- **Validate preconditions continuously**: Ensure all previous steps still hold true while executing a sequence
32+
- **Handle dynamic environments**: Re-check environmental conditions that might change during execution
33+
- **Maintain safety checks**: For critical operations where all conditions must remain valid throughout
34+
35+
**Example**: A character needs to pick up and use an item that might be taken by another character. Using `SequenceReactiveComposite` would re-check if the item is still available before attempting to use it.
36+
37+
```
38+
SequenceReactiveComposite
39+
β”œβ”€ IsItemAvailable (Condition)
40+
β”œβ”€ MoveToItem (Action: running)
41+
└─ UseItem (Action)
42+
```
43+
44+
#### When to Use "Tick Again" Behavior
45+
Choose a sequence with "tick again" behavior when you need to:
46+
47+
- **Optimize performance**: Avoid redundant checks of conditions that won't change
48+
- **Complete multi-step procedures**: Ensure a procedure completes without unnecessary rechecking
49+
- **Create predictable, deterministic behavior**: When you want guaranteed completion of a series of steps
50+
51+
**Example**: A character performing a complex animation sequence that should complete regardless of minor environmental changes would benefit from `SequenceStarComposite`.
52+
53+
```
54+
SequenceStarComposite
55+
β”œβ”€ StartAnimation (Action: success)
56+
β”œβ”€ PlayMainAnimation (Action: running)
57+
└─ EndAnimation (Action)
58+
```
59+
60+
The performance benefits of "tick again" come at the cost of responsiveness to changing conditions, while "restart" provides better adaptability but with higher computational overhead.
61+
2062
## Sequence Random
2163
The Sequence Random node behaves similarly to the Sequence Star node, but instead of executing its children in the given order, it executes them in a random order.
2264

0 commit comments

Comments
Β (0)