I’m looking for a way to nicely handle events that are based on animations in some way. This could be footstep sounds for example or starting and stopping particle emitters at given times within an animation.
I’d like to avoid hardwiring this into code, and rather leave it to the animator.
If I remember correctly the Unreal engine has built-in support for anim events.
Has anybody worked on something like this, or has some pointers on where to begin?
I was just asking about this myself a few weeks back. The short answer is no, there’s not built-in easy solution at the moment. While this isn’t the wish list forum, I’m gonna go on record now and say that this would be a great feature to have - in the same interface that we designate start/end frames for imported animation clips, be able to flag certain frames to trigger functions from a script somewhere for such things as particles, sounds, network RPC’s and so on. This is a standard feature in the studios I’ve worked.
It can be worked around though for most simple things. Triggering a particle, sound, or whatever at the exact same time you tell an animation to start is easy enough, so you either split your animations in such a way that the ‘seams’ land on your events (very ugly in the case of a walk cycle and foot sounds, but fine for firing a gun and spawning a muzzle flash) OR you set up whatever function you’re using to trigger sounds/particles with an argument that acts as a time offset, so if you know a sound needs to happen 1/2 second in to an animation, you sort of queue it up in advance at the time the animation begins… of course if that animation gets interrupted and the sound should be cancelled you’d need a provision for that too.
Thanks, Mr. Animator; yeah it sound like major pain
For now I thought of a solution, which is basically like an Animation Manager script, that would handle AnimEvents.
The events themselves would either be exported from the 3D anim. program of choice (in our case it’s Max, so they would be placed on a note track or similar). The other possibility would be to just expose the “AnimEvent” class in an array and fill up the manager with events using Unity’s Inspector.
I got a dummy version of this working already, but the firing and managing of events is very complicated and I’m thinking if it’s even worth to finish this at all. Problems arise when you have lots of objects, playing animations blending them etc., this isn’t something you would want to do on the scripting level…
Maybe I’ll make a simplified version of this, but I too think that this should really be part of the engine itself.
We’ve had the same need here, and what we did for now is we have some dummies (folders) in the model, that the animator moves when he wants to fire an event.
This is the closest we managed to simulating a 0/1 toggle; Cheetah (and I suppose, the FBX format itself) supports the animation of boolean parameters, but any custom attribute is ignored by Unity on importation (basically you can only access position, rotation and scale).
I actually did a super limited Cheetah script to help the animator “declare” the events in the model, I guess it could be done in any modeler that allows scripting.
Then, I scripted a “listener” in Unity, that watches the dummies positions, and fire events when they move. It works great for “punctual” events, and in theory you can even have “timed” events (ie events with a lifespan, like at t0 it triggers on, then later at t1 it triggers off).
I love it because we don’t have to worry about time and frames and stuff (we use takes so no clip-cutting on import either), the event is actually wired into the animation, and the animator worries about it, not the scripter.
But this is still very hack-ish, we haven’t had time to test it thoroughly. For example I’m not too sure what’ll happen with blending (especially with time events): if an event dummy is partly up and then blending distorts its position, will it fire? should it? etc.
For punctual events the detection is pretty good (one frame down, next frame up, next frame down again), so it’s mostly bad luck if an event comes up just when blending occurs.
… still… hack hack hack… too bad about the custom attributes…