Multiple Behaviour Trees

NodeCanvas Forums General Discussion Multiple Behaviour Trees

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #9298

    Hi,

    We have our own FSM, and wanted to use it alongside NodeCanvas.

    I’ve only just started to look into NC though. Do I need multiple behaviour tree owners on a gameobject for each state, and each of those has a single behaviour tree.

    ie. is it a one-to-one relationship between behaviour-tree-owner and a behaviour-tree? and I just set them all to do nothing on-enable and disable run-forever, then enable a specific one based on our current state?

    Many thanks,

    #9305
    Gavalakis
    Keymaster

    Hello and welcome 🙂

    A single BehaviourTreeOwner is needed regardless of the number of BehaviourTrees you are going to run with it.
    Think of it like the Animation component from which you can run any number of different AnimationClips.
    The BehaviourTreeOwner has a SwitchBehaviour method to switch between different BehaviourTrees at runtime.
    Here is an example:

    Let me know if that’s what you are after 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

    #9304

    Aha brilliant! Now I’m onboard, I didn’t even realise that behaviourtrees were child gameobjects that I could duplicate and edit, doh!

    So essentially to loosely couple it all I just needed ..

    So the only question left is to talk back to the state machine when a transition is required, is this left to our own discretion and just hook up events / messages as needed, or is there a preferred method?

    Many thanks!

    #9303
    Gavalakis
    Keymaster

    Yep, that code is totaly fine 🙂

    BehaviourTrees are objects of their own. While by default they are created as a child, they don’t have to be child if you don’t want them to. You can place them wherever you want. The rest will be done for you in runtime :), but then you will need another way to reference them, which well… is realy easy.

    There are many ways to communicate from the BT to your FSM. First of all, you can pass a callback for when the BT is finished in case you set it to RunOnce.

    You can also check the root status of the BT by the rootStatus property and respond accordingly.
    You can simply use a SendMessage from within a BT action and catch that message on the agent or any other game object.

    You can use the blackboard which the BTs will be using and check it’s variables like so:

    You can use ScriptControl Tasks to call a function on one of you components and in consequence trigger a transition.
    Last but not least, you can use the NC FSMs with nested BTs 😛 🙂

    Let me know if you need more possible ways or something specific.

    Join us on Discord: https://discord.gg/97q2Rjh

    #9302

    Right well, that’s officially embarrassing that I missed noticing there was a callback haha. Although the callback would only notify of a single ‘event’, ie. “we’ve ended’, I’ll just set a BB string variable to the transition it should use, then call the callback and let the statemachine use that, so should work just fine. Plus it exposes the last transition to us, which is distinctly very helpful for debugging.

    I was just looking at your execute-function instead as to all intents and purposes that actually would be perfect, however we use inner-classes for sub states (so for example one global state, say class AI, then three sub states as inner-classes ai_Follow, ai_Chase,.. ai_WhatEvs), and the execute-function methods don’t appear to include nestedtypes so was just adding that in..

    ie. in EditorUtils.ShowMethodSelectionMenu…

    .. and adding the inner-class methods there along with the GetType().GetMethods…

    However having just checked this post I’m pretty sure I have all I need to get by tbh 🙂

    Many thanks for all the help, would be great to see nestedtype methods in the list so we can use execute-function for those, and especially since unity’s send/receive message doesn’t support inner-classes either, however I’m more than happy right now and can crack on I reckon.

    Cheers!

    #9301
    Gavalakis
    Keymaster

    Heh, Dont worry 🙂

    Yes that callback would be useful for when you want to know if the state is finished for example, considering that the state is using a BT.
    I’ve added nested type method selection to the TODO list. It would be indeed helpfull 🙂

    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #9300

    Best support I’ve ever had. Brilliant, thankyou!

    #9299
    Gavalakis
    Keymaster

    You are welcome! 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.