Hello, sorry if I'm asking a question that has already been answered but I couldn't find an answer in the forum.
I bought BD several years ago but I'm starting to use it only now for my game... which has quite a lot of requirements. One of them being that an NPC should be able to do tasks recursively. Here is a quick example:
1. The NPC walks to a position.
2. There is a closed and locked door blocking its path and it detects it.
3. The NPC knows where the key is.
4. The NPC walks to where the key is stored.
5. Problem is, the key is in a chest that is also locked, so the NPC needs that key too. Call a new tree that starts at step 3.
Step 5 is a recursive call because the key to the door is locked in a chest which key could also be locked in a chest and so on... you get the picture. This is an extreme example but there are many other applications of this case and I don't see how to implement it in Behavior Designer with true recursivity (meaning executing a local tree with its local variables and context switching).
I've experimented with shared variables but that's not good for the purpose since they're global in their own tree. I've looked into external behavior trees but they seem static and consume their references when instantiated so no way to repeat them indefinitely in the same parent tree. I don't really want to instantiate new behavior tree components dynamically in an NPC every time I must call a tree recursively either (even though that might solve the problem since each BD component has its own context after all).
Is there an easy way to achieve true recursivity with BD?
I'd like to point out that I made my own behavior tree engine in another language for a commercial product of mine but it is very different from BD. It is event-driven and relies on textual trees (written like programs in their own simple language), and recursivity is what it is based on so it handles this case above natively and easily. I will port it to C# to use into my Unity game if I have to but it would be a shame since I already bought BD and I like its other features, and I don't really want to spend time on porting code.
Thanks!
I bought BD several years ago but I'm starting to use it only now for my game... which has quite a lot of requirements. One of them being that an NPC should be able to do tasks recursively. Here is a quick example:
1. The NPC walks to a position.
2. There is a closed and locked door blocking its path and it detects it.
3. The NPC knows where the key is.
4. The NPC walks to where the key is stored.
5. Problem is, the key is in a chest that is also locked, so the NPC needs that key too. Call a new tree that starts at step 3.
Step 5 is a recursive call because the key to the door is locked in a chest which key could also be locked in a chest and so on... you get the picture. This is an extreme example but there are many other applications of this case and I don't see how to implement it in Behavior Designer with true recursivity (meaning executing a local tree with its local variables and context switching).
I've experimented with shared variables but that's not good for the purpose since they're global in their own tree. I've looked into external behavior trees but they seem static and consume their references when instantiated so no way to repeat them indefinitely in the same parent tree. I don't really want to instantiate new behavior tree components dynamically in an NPC every time I must call a tree recursively either (even though that might solve the problem since each BD component has its own context after all).
Is there an easy way to achieve true recursivity with BD?
I'd like to point out that I made my own behavior tree engine in another language for a commercial product of mine but it is very different from BD. It is event-driven and relies on textual trees (written like programs in their own simple language), and recursivity is what it is based on so it handles this case above natively and easily. I will port it to C# to use into my Unity game if I have to but it would be a shame since I already bought BD and I like its other features, and I don't really want to spend time on porting code.
Thanks!