Add an "OnExit" callback for ActionTask

NodeCanvas Forums Support Add an "OnExit" callback for ActionTask

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #14459
    Driiade
    Participant

    Hello there 🙂

    I have an other demand (sorry :'( )
    Will it be possible to have a sort of “OnExit” when for example FSM Exit the current state, or BT change its running leap ?

    It will be convenient to have it with the case where you want an action to finish, but you also want a callback when the state exit. Actually we have a OnStop callback only when the action End, but not when exiting the current running state.

    Ask me if not clear.

    Cheers.

    #14463
    Gavalakis
    Keymaster

    Hello,

    Sorry for the late reply due to summer vacation and no problem! 🙂

    Hmm… Right now, when a state exits, EndAction is called on all ActionTasks assigned to the state. However, if the ActionTask is already stopped, the callback OnStop is not called again (to avoid calling it multiple times). I could add something like “OnForcedStop” which will be called regardless whether or not the action is still running, which will result in it being called for example, when the FSM state exists as well.

    Here are the changes I’ve made if you want to please try out and let me know if that indeed works for you the way you want:

    Please open up ActionTask.cs and change lined #128-130 to be like this:

    Then also, of course add a virtual method at the end like so:

    Let me know how that works for you.

    Thanks!

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

    #14464
    Driiade
    Participant

    It’s more general I think.

    It’s when fsm current state stop. Not when the action task is running and forced to stop. It will be called on all ActionTask without checking their state when the actual FSM current state stop.

    So we can do something regardless of the state of the actionTask but in regard of the state of the FSM State.

    And for BT, it will be when the BT change its current running “leaf”.

    Scenario on our game : Launch a sound on Execute (when the state begin in fact) -> Stop the sound when the current state stop.
    For the moment I have a empty running Sound Task because if I EndAction, my sound End… because I can’t detect the actual End Of State.

    #14465
    Driiade
    Participant

    It’s like the SuperActionState OnExit. But the code will be on ActionTask instead.

    #14491
    Gavalakis
    Keymaster

    Hello and very sorry for late reply due to summer vacation!

    Maybe the naming of the method (“OnForcedStop”) brings confusion, but I think this does what you want at least in the FSMs context. It should be called when the state exits/stops (even if the action is already stopped). Have you tried adding this to check it out?

    Regarding Behaviour Trees this won’t work at all the way you suggest indeed however. This (OnForcedStop) is instead called when the action node (or tree altogether) resets. But in Behaviour Trees, the leaf is changing when the action has finished (returns Success, Failure or anything but Running), in which case the normal OnStop callback is called.

    Can you please give the above change in my post a check in the context of FSMs if you haven’t already and let me know?

    Thank you.

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

    #14507
    Driiade
    Participant

    Hello,

    I Will keep my solution, since it will not work on BT ^^

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