Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by RElam 1 · Feb 06, 2010 at 06:32 PM · animation

One parameter limit on animation event functions temporary?

Is the limitation on the number of parameters for animation event function calls (currently, only one parameter functions are exposed) temporary? I have several cases where multiple parameters would make my life much easier, and wondering if I should go ahead and work out hacks around this, or delay those for an update.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by duck · Feb 07, 2010 at 03:14 PM

I don't see any indication that this would be a temporary implementation. I think because the Animation Event can take an "Object Reference" as the parameter, this essentially allows you to pass any kind and amount of data you like.

Simply put the data into an array, or create your own custom class to contain the data and pass an instance of that. If that's what you were considering doing already, there's no need to think of it as a "hack" - it's common practice!

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RElam 1 · Feb 07, 2010 at 09:57 PM 1
Share

It's common practice because it has to be, and I'd call it a hack for the simple reason that it's a hack (being forced to do it doesn't change it's level of elegance). I agree that it can allow the function to do anything, just not in a clean or efficient way, which is what makes using the animation event so attractive to me.

Thanks for the response, but I'm looking for an official one. I agree that there's no indication it's temporary, but also none that it's permanent, which is why I'm asking.

avatar image duck ♦♦ · Feb 07, 2010 at 10:05 PM 0
Share

I understand that it can be a matter of subjective aesthetic, but to me, a custom class or struct designed to carry a collection of related data often seems more elegant than having that data split across an arbitrary number of parameters. However, I concede that it still may be the case your particular requirements (and since you haven't described them, I can only speculate) may be more suited to multiple parameters. I hope you find a more satisfactory answer! :-)

avatar image RElam 1 · Feb 07, 2010 at 10:39 PM 0
Share

Upon further thought, I'd agree with you, if there was an option for that class to be instanced and managed by the Animation Event, and saved with the animation. The only way I've gotten it to work is by attaching a script to a gameobject, and referencing that, which is very clunky to manage, since to review/change settings you have to select the game object, deselecting what you're animating.

I'd say that if I could have animation event create/manage an instance, and have an inspector for it at the bottom of the window, that'd be best, wouldn't break animations by adding/changing params.

avatar image mk26 · Jan 21, 2016 at 06:27 AM 0
Share

for code reference check this http://answers.unity3d.com/questions/722410/animation-events-how-is-the-parameter-animationeve.html

avatar image Ash-Blue · Jan 24, 2016 at 08:25 AM 1
Share

Something may have changed with the API for Animation Events. As you can't pass an object reference anymore.

avatar image
3

Answer by Tommyph1208 · Jan 24, 2014 at 01:40 PM

Reviving this for people like me who may stumble upon it on Google... Now (maybe also back then) you can pass an AnimationEvent in the function called by your animation event... Sounds funky I know... The animation even is a collection of info and includes:

an int a float a string and an object reference

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kerihobo · Aug 16, 2015 at 04:44 AM 1
Share

as a follow up to this:

http://answers.unity3d.com/questions/722410/animation-events-how-is-the-parameter-animationeve.html

avatar image
2

Answer by Ash-Blue · Jan 24, 2016 at 08:15 AM

After some testing it looks like Unity only allows AnimationEvent, int, float, and string. You cannot pass in an object reference as mentioned in another answer. That said, here are your options.

  1. The "easiest" solution at the moment for multiple parameters is to use an AnimationEvent, this is pretty inefficient if you need multiple ints, float, strings, or other complex data. Details: http://docs.unity3d.com/ScriptReference/AnimationEvent.html

  2. Parse a string with multiple values separated by a comma (slow, messy, and error prone).

  3. Write individual functions for every event you need (circumventing params). Very messy for complex events.

  4. Use setters to alter the data in events, could result in a ton of events and more mess.

In short there is no good solution until Unity expands on the animation window's serialization API. Best of luck.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Raikir-i-sh · Jan 25 at 04:00 AM 0
Share

u should've also included, Object ref as a option. As it can include all data that a player might need. And , i don't think a single animation event was designed to multiple data changes. I mean to say if in a player atk animation , a collider hits enemy mid-way then that should call OnCollisionEnter() insted of using anim-event at such place. Basically, imo it is made to do small trigger events .

avatar image
0

Answer by Serinx · Jun 10, 2018 at 11:00 PM

I don't know if this is correct but what I did is create a MyAnimationEvents class, this class holds all of the event information I need (damage, radius, prefabs, names etc). I made prefabs of all the various events which only have this script attached e.g.

animEventStandardAttack - damage = 1f, radius = 1f, particleSystem = blood, name = "standard"

animEventHeavyAttack - damage = 2f, radius = 2f, particleSystem = bigBlood, name = "heavy"

When I call the animation event, I pass in the prefab I want. The function instantiates the prefab, grabs the values from it and uses them as necessary. Heres the code I'm using in the animation event:

     public void DoDamage(GameObject animEventGO)
     {
         MyAnimationEvent animEvent = GameObject.Instantiate(animEventGO).GetComponent<MyAnimationEvent>();
         if (animEvent.damage == 0) animEvent.damage = 1f;
         if (animEvent.radius == 0) animEvent.radius = 1f;
 
         MeleeWeapon wep = gameObject.GetComponent<Inventory>().equippedItem.GetComponent<MeleeWeapon>();
         wep.DoDamage(animEvent.damage, animEvent.radius);
     }

Hope this helps someone!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by nanocba83 · Jul 14, 2018 at 03:13 AM

Inspired by @Serinx answer, this is how I'm doing it now:

  1. Create an animation event class with the information you need

  2. Allow that class to be used to create assets out of it by adding [CreateAssetMenu (menuName = your_menu_name)] on top of its declaration

  3. Create as many animation events as you wish by right-clicking on your project and choosing the animation event from the corresponding menu

  4. On the script you have the event handler, you can now write something like this:

public void OnAnimationEvent(MyAnimationEvent animationEvent) { //Use it directly, without the need of instantiating }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Can I make animations snap to a frame? 1 Answer

How to select an animation clip by index number? 7 Answers

Changing size of model with animation 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges