Aseprite2Unity icon indicating copy to clipboard operation
Aseprite2Unity copied to clipboard

Create animation events from cel user data

Open aschearer opened this issue 3 years ago • 5 comments

Currently it's not possible to add animation events to the imported clips. Animation events are pretty critical. For example, if you want to emit foot steps at specific frames, or if you want to trigger an attack at a specific moment. Aseprite has support for custom "user data" per cel. It would be super handy to connect that to the importer and programmatically add events to the imported clips. Unity has support for this, but I couldn't sort out how to read the cel's user data -- any pointers? Happy to create a pull request once unblocked.

var animationEvent = new AnimationEvent();
animationEvent.time = time;
animationEvent.functionName = "foobar";
var events = new List<AnimationEvent>();
events.Add(animationEvent);
AnimationUtility.SetAnimationEvents(clip, events.ToArray());

aschearer avatar Feb 25 '22 17:02 aschearer

Hi there, @aschearer. I can take a look at this. I don't currently use userData for anything but it seems it can be done. I'd have to find a way to attach the proper event to the proper clip but I don't expect it to be too bad.

Seanba avatar Feb 25 '22 22:02 Seanba

Cool! Quickly dabbling I found the above code snippet will add an event to the designated time in the animation clip -- I tested with start and end. So the main thing is just how to get the userData during import. How did you figure out how many bytes to read, etc.?

aschearer avatar Feb 25 '22 23:02 aschearer

Hello, @aschearer. I just pushed out version 1.2.0 of Aseprite2Unity which includes support for animation events. Further, the MegaDad example now uses animation events to play sound effects. See the example for further details and let me know how this works out for you.

https://seanba.itch.io/aseprite2unity/devlog/351816/aseprite-version-120

Seanba avatar Feb 27 '22 01:02 Seanba

Wow you're a boss! 🎉

aschearer avatar Feb 27 '22 21:02 aschearer

This is a great addition. Do events happen to support arguments?

MabLuxx avatar Nov 09 '22 00:11 MabLuxx