Get all events in Animations to loop, is possible?

Hi!

Is possible to do a foreach in Events inserted in animations?

I have some Events in my animation to stop in pre-defined frames…

But by script I dont know where these Events are, in what frame is it.

So if possible maybe a loop for each can solve. If was possible to use more then one variable in functions that Events can call will be nice because we can just set prev==10; actual==20; next==30; just for instance. But I tried and Events only accept one argument.

The goal is jump to the next position or to the prev position.

In my animation, I can forward or backward clicking in buttons “prev” or “next” that will play anim until next Event that will call a function that stop animation in that frame. But today my anim need to play until hit the next Event. I need also to jump to next Event.

Thank you!

Hi there!

I’m not sure about what you’re doing exactly, and I believe what you’re trying to achieve should be done with something else that animation events.
Still, here’s an answer to your questions, if this can help.

It seems possible to loop through all events of an AnimationClip, using this code (I did not test it, but I suppose it works fine since there’s nothing special about it). Of course you don’t want to use new() for an AnimationClip, you want to reference the desired clip another way, this is just to show how the loop looks.

AnimationClip clip = new AnimationClip();
foreach (AnimationEvent clipEvent in clip.events)
{
    Debug.Log(clipEvent.time);
    Debug.Log(clipEvent.functionName);
    // etc.
}

About an event having more than 1 parameter, to my knowledge this is not possible. What you can do is use a ScriptableObject as parameter, and in this ScriptableObject you can have as many parameters as you want.
So for instance, your ScriptableObject could look like this:

[CreateAssetMenu(fileName = "New Event Parameters", menuName = "Event Parameters")]
public class EventParameters : ScriptableObject
{
    public float ParameterA;
    public float ParameterB;
    public float ParameterC;
}

And the listener method like this:

public void SomeEventListener(EventParameters parameters)
{
    Debug.Log(parameters.ParameterA);
}

Once again, even though I don’t understand your problem precisely, I’m pretty sure animation events are not what you’d want to use, but I hope this can help.

1 Like

This is because my english is so bad that complicate everything…

But you are right, With your code I can get all Events in one clip. So I can get one specific Event and get the specific time. Using Play we can stop at this time.

The all idea about what I tried to explain is basically to create one similar tool like PowerPoint. We have slides in PowerPoint. Each slide is basically one picture. So the all presentation is a compilation of images. To do it in unity is very simple…

But instead of we have one compilation of images, if we had one single animation like a “step by step”. So we stop at every step and only start the next step when click in “play” or “next” button again.

Ok, we can do each of these steps individual and call with triggers. But in some cases is much more simple to use one single animation and stopping at specific frames.

But you show the path…Thank you Sr…