Generating subtasks

nanodeath

New member
When a particular task starts, I want to generate subtasks in the OnStart() method of that task that causes child tasks to be created. For example, if the AI character is moving to some destination, but during pathfinding finds some doors in the way, I want to create tasks "MoveToObject(door), OpenDoor(door), MoveToObject(originalDestination)" kind of thing.

I can see a couple ways to achieve this:
1. Subclass Sequence and call AddChild(...) in OnStart(). This seems like it should work, but I'm getting some unexpected BehaviorManager childrenIndexes errors, so maybe that's not well-supported. Even if this did work, the graphical editor shows a red X on the node because it's lacking children (which are generated at runtime).
2. Model MoveToObject and OpenDoor not as Behavior Designer tasks, but vanilla C# classes. This should work fine, but would mean reimplementing parts of Sequence myself to keep track of whether the "subtask" has completed or not and then move on to the next. If I wanted a top-level MoveToObject task, I'd also need to create a duplicative MoveToObjectTask that simply wraps the vanilla MoveToObject subtask. This is fine though.
3. Something else?

(as an aside, in this particular example I might simply pathfind the character all the way from start to finish and just automatically open doors along the way, but there might be other cases where that behavior isn't possible)

This seems like it'd be a common ask, but I'm having some trouble finding material that covers it. Thanks in advance for any help.
 
Top