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?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
///Ends the action either in success or failure. Ending with null means that it's a cancel/interrupt.
///Null is used by the external system. You should use true or false when calling EndAction within it.
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:
1
2
3
OnStop(success==null);
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.
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.
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!
Join us on Discord: https://discord.gg/97q2Rjh
Author
Posts
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Login
Register
By registering on this website you agree to our Privacy Policy.