Possible alternative to animation events?

I was wondering if it would be easier to add a property to your animation and change the speed variable that way? I understand animation events are useful for calling methods that may deal damage or do anything more than simply change a variable. However, it seems that adding a property is a better way to change variables within a script because it saves you making a new public method and having to mess around with the clunky string names.

[Edit] However, it seems that adding a property only works if the variable is serialized.

Anyone else have opinions on this?

1 Like

Hi Sean,

I’m not sure if I understood you correctly but you cannot add any properties to the animation. Maybe you can add a component to it and access a property of that component/instance but I have not tested that.

Neither Unity nor the animation know anything about “speed”. “Speed” is meaningless without a context. The context is your script.

1 Like

This is what i meant by adding properties to an animation. Speed is the name of a serialized variable within my Attacker class. My Lizard_Walk animation sets the variable to 1 and my Lizard_Spawn animation sets the variable to 0. Then the movement is handled within the script as usual.

Is this a good way of doing things?

1 Like

I have to admit that I didn’t know that this was possible. If it works, it’s a good solution. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms