x


Call a function at a certain frame in animation without Animation Events?

Is there a way to call a function at a certain frame of a character's animation?

Pseudo-Example:

if (hero.animation("castingmagic").frame = 8)
      SpawnFireBall();

I mainly want something like this for animations that take while to complete or have multple attack to execute the infliction only when the animation is in a particular frame?

Another psuedo-example:

if (hero.animation("flinching").lastframe)
     NotFlinching();

Something like this would be helpful for my animations that are several frames long and I don't want the character to move until the end of the animation.

more ▼

asked Mar 21 '11 at 12:15 AM

SirVictory gravatar image

SirVictory
1.7k 66 77 104

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

In short: No.
Animations are timebased in Unity. So there is no information about keyframes at runtime. Why don't you want to use Events?

The events are made For such things. Well, you can compare the current animation time if it's in a certain range but it would be a lot more work and it wouldn't be as reliable as animation events. If you want to know the exact (graphical-) frame when an animation has finished you would have to use ClampForever and stop the animation manually. Otherwise you will never reach the end of the animation.

more ▼

answered Mar 21 '11 at 02:13 AM

Bunny83 gravatar image

Bunny83
45.5k 11 49 207

It was mostly out of laziness. I was curious to see if it were possible without animation events, but I guess I can make a script at the area of the attack that does a SendMessage() and have it toggle a flag or something...

Mar 21 '11 at 09:25 AM SirVictory
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3807
x478
x166
x76
x16

asked: Mar 21 '11 at 12:15 AM

Seen: 1485 times

Last Updated: Mar 21 '11 at 12:15 AM