Switch Composite Options Constrained

NodeCanvas Forums General Discussion Switch Composite Options Constrained

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #8901
    Sanity
    Participant

    Hi,

    I would like to see Switch Composite have options to switch based on conditions or events more specifically.

    Right now I am trying have my AI switch trees based on Node Canvas Events, first I thought Selector will do great, but realized that if it receives different event while it is running one right now, it does not interrupt current running node and ignore event. Can’t figure out an elegant way to do this… Will Gnaw on it for a while more tho!

    P.S. Loving node canvas! 🙂

    #8911
    Sanity
    Participant

    While I was brainstorming this I realized that it wold be great if guard has an option to interrupt all other branches with that token and run this one instead.

    #8910
    Sanity
    Participant

    Current Set Up

    Here is what I have right now, basically events change index of switch, when switch is done executing it’s task it switches its own index into out of range number.

    Is there a better way to do this?

    #8909
    Sanity
    Participant
    #8908
    Gavalakis
    Keymaster

    Hey.

    Sorry for late reply.
    Actualy your first idea is correct. You can use Selector for this, but remeber to make it Dynamic. If the received event is lower in priority (left) than the current Running child, then it will interrupt that child. The whole behaviour tree parading is based on layering behaviours in priorities such as this.
    I have attached an image for you for a possible approach.

    So in this example, Attack is the highest priority behaviour. If the unit is still attacking, firing a Gather event will not have any meaning, because attack is more important. If though the unity was patroling and we fire a Gather or Attack, since both are more important, Patrol will be interrupted and that other behaviour will start.
    Similarily, if the last event is consumed and the relevant behaviour is done, thus the unity has nothing to do, it just stays idle without an event needed for that.

    This is what behaviour trees are based upon really 🙂

    Let me know if that sounds usefull or not relevant to your situation maybe.

    Cheers!

    (ps: the guard decorator is mostly there as a resource guard for when using multiple BTs running in the same owner 🙂
    In truth there are really countless types of nodes you can create with BTs, especialy decorators. While I have come up with some more, I really dont want to include more as to not be confusing what to use where. Instead I was even thinking of removing some, at least from the main package.)

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

    #8907
    Sanity
    Participant

    Thanks Gavalakis!

    The issue I am having with this is that I am using events to send orders to the graphOwner (like RTS move here or attack this). Which means that I want my AI to stop what hes doing, So there are no priorities, just listen to the most recent one.

    Is this out of behavior tree scope?

    #8906
    Gavalakis
    Keymaster

    Hey,

    You are welcome.
    I see what you mean that priorities are not important for this instance since its not exactly an autonomous agent.
    Without priorities taken into account then indeed the best solution is the Switch composite and similar to what you have, Although I would certainly use an enum.
    I have attached the BT image for you here.
    The Variable “command” seen is a custom enum:

    With the events we set the last command issued and then Switch it to take action.
    Of course we should provide a deafult like Stop/Idle or similar to start with.

    I hope this helps 🙂

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

    #8905
    Gavalakis
    Keymaster

    Also to add up, and like you previously suggested, there could certainly be a custom Switch Selector that would work like you originaly though Selector would. I can provide you with such a node if you like. Havent tried to create it yet, but I suppose it can exist 🙂

    Cheers!

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

    #8904
    Sanity
    Participant

    I would love node like that, but your suggestion worked well enough for me. I Assume you’re busy up to ears with the NC 2.0 release and you’re already giving me great help.

    That being said I am having some really strange behavior from the set up you suggested.

    Here is my Tree right now.
    https://onedrive.live.com/redir?resid=2401AF620DF7FD1E!102519&authkey=!AFh2D3IHGa2lclg&v=3&ithint=photo%2cpng

    It behaves fine until the target it is attacking destroyed itself, then it gets stuck at the state the pic is off and throws an error every frame. Saying I am trying to access BehaviorTree that has been destroyed essentially. Strangely when I click on the error it takes me to the OnCheck() method of The CheckDistanceCondition… But it was not supposed to be run at all since it’s parent sequencer should have failed from the null check I did before?

    In addition to that I am getting those yellow Warning signs on my nodes, because the _target is null (it goes away if I assign something for it) am I using them right? Are these nodes not supposed to handle dynamically assigned variables?

    Thanks ahead of time mate 😉

    #8903
    Sanity
    Participant

    Hey, I think I isolated whats causing issue. The CheckVariable<T> Condition does not work for checking if object is null. I say this because when I wrote simple check condition and used that, it seemed to work fine.

    #8902
    Gavalakis
    Keymaster

    Hello,

    You are correct about the CheckVariable and unity Objects. Here is a CheckUnityObject condition to use. I will also include it in the next version:

    Also, I would like to suggest that in your tree you can simple use the CheckUnityObject and leave valueB null instead of using a blackboard variable that is null 🙂

    Cheers and thanks!

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

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