OnInterrupt callback in ActionTask

Forums 💬 NodeCanvas ⚙️ Support OnInterrupt callback in ActionTask

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17152
    w
    Participant

      Hi,

      I have a custom action task that plays an audio along with an animation clip and I would like to implement a fade out coroutine for the task upon interruption so that the animation and audio can ease out smoothly. Currently this is not possible as there’s no OnInterrupt function in ActionTask.

      I see in the code that it’s possible to determine whether a task finishes by itself or is interrupted, so I guess potentially we could add a callback there?

      Thanks!

      #17155
      Gavalakis
      Keymaster

        Hey,

        Indeed, we could implement an interrupt callback and I think that makes sense (although never used personally before) 🙂
        Instead of a separate callback though, I think that it would be better to provide an argument to the OnStop callback (bool interrupted), so that in code you can discern whether the OnStop was called due to interruption or not, instead of calling both OnStop and OnInterrupt.
        Here are the changes to make please:

        1) Change the final line of the EndAction method to this:

        2) Add this new OnStop method. We can’t change the existing one due to backwards compatibility.

        This way, you can either override OnStop as before (and thus all existing tasks will still work), or override the OnStop(bool interrupted) method, if you care to know about the interruption in your action task.

        Let me know if that works for you.
        Thanks!

        #17154
        w
        Participant

          Hey Gavalakis,

          Thanks for your fast response. Your solution makes perfect sense. I will go ahead and add it to the code.
          Do you plan to include this change in the next version of NodeCanvas? If so we don’t have to pay extra attention when upgrading.

          Thanks

          #17153
          Gavalakis
          Keymaster

            Hello,

            You are very welcome.
            Yes, this change will exist in the next version since I found it to be a nice suggestion, so no worries about updating manually 🙂
            Thank you!

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