Reply To: Injecting a subtree in runtime?

NodeCanvas Forums General Discussion Injecting a subtree in runtime? Reply To: Injecting a subtree in runtime?

#9142
zxc

    That’s also a solution, but I don’t feel it takes advantage of the behaviour tree modularity. Weapons is just a simple example, but consider dynamic usage of the environment – for instance a bomb placed in a level, that an AI Enemy can shoot to kill a player; or a terminal it can hack for some other advantage. I see it that the behaviours associated with these special objects should be BTs that are stored and coded in the objects. AI just “takes” those BTs and injects them into the main BT.

    Not that I invented this approach. I just “heard” that that’s how it’s done sometimes and wanted to test it :). I’m currently listening to AIGameDev podcasts like crazy and also this Gamasutra article suggests similar approach.

    Anyway I managed to inject a subtree with a following code (simple stuff actually):
    _treeowner.BT.GetNodeWithTag<BTSubTree>("I").nestedGraph = subTree;
    So I have an empty subTree node in the graph, thats tagged “I”. In runtime I find this node and replace the SubTree with a reference to my custom weapon BT. Only drawback is that I need to create a “stub” SubTree that fails when called – so that the injection point doesn’t return SUCCESS when there is no tree injected.

    If I could specify the return value of the empty SubTree Node, that would be great. Then the unused injection points wouldn’t have to be handled additionally.