So noticed a strange behaviour with a nested subtree node.
Steps:
1: Switch a subtree node to another behaviourtree with a subtree node in play mode
2: exit play mode
3: inspect subtree node in the behaviourtree asset
Result:
The nested subtree node loses its reference to the behaviourtree that was in it, resulting in null after a single play mode.
Is there a better way to switch Subtrees at runtime? Is there some command im missing when switching/unplaying?
Any insight into this would help me greatly, thanks!
I should be clear, the subTreeNode that is losing its reference is NOT the subTreeNode that i change, but the subTreeNode is inside one of the behaviourtrees that is put into the subTreeNode
Hello,
Thanks for reporting this. I was able to reproduce this problem. This appears to be happening when you swap the target SubTree reference when the SubTree Node in which you swap the reference is already *Running*.
I will of course need to fix that and add a failsafe check, but please avoid swapping the target SubTree reference (either manually or through variables) *while it is Running*, because it will result in unintended behavior until I fix this.
Is there a good way for me to swap trees at runtime, like temporarily stopping the node while a swap is ocurring? maybe multiple branches that can Queue trees dynamically?
Hello,
Sorry for the late reply.
You can stop the behaviour tree (owner) before switching the target graph if you do have to do it manually in the editor while the game is running. Otherwise, you can of course use blackboard variables to switch the trees in runtime, which is how trees are intended to be switched in runtime if required.
Hi Gavalakis, i appreciate the time and effort you are putting into keeping the forums going and answering questions, so dont worry!
Ill try to explain my process as best i can and you can tell me if i am doing something wrong with my approach, or if i should abandon the design entirely and try to re-think the way i’m doing things.
Reactions and actions, i switch out the Mission Subnode tree depending on reactions which causes the tree to lose its reference even if its in the BB.
I add the reactions at start from the chosen AI profile
This is the designer interface, when creating a new AI profile (Captain), you match missions to two sets of flag enums for who is doing the action, and what action it is.
I tried stopping the tree before switching, Which stopped the references from dissapearing like you said, but it causes a 1 frame infinite loop error on the AI trunk start node that i’ve not been able to circumvent.
Thanks for the follow up and for the further explanation.
I have made some quick changes to the SubTree node (attached for you here) and now changing the target SubTree, even while the SubTree node is running -both in editor or in runtime- should work better (no reference lost and no need to stop/restart).
Please note though, that if the change happens while the SubTree node is running, the actual change will take place only once after the previous target SubTree is finished first (return anything other than Running).
Can you please test it out and let me know how it works for you?
Yes this works!
I dont seem to be losing the references anymore, this frees up the way im able to design around BT’s as specific responses to situations.