Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Dengar · Apr 13, 2014 at 03:59 PM · animation2dspritetransitionanimationevent

Is it possible to turn off/suppress event calls in an animation at runtime?

Okay so I'm trying to make my animations as fluid as possible. I have a 2D Prefab consisting of various sprites to form one sprite where the parts can be moved around during animation. It also uses animation events to call a script that swaps the textures of the individual sprites during the animations, such as a hand opening and closing. The problem arises when I transition from one animation state to another. During the transition, it runs animation events from both animations, which sometimes causes the sprite to "spasm", IE it starts to flicker between the sprites that the first animation wants, and the sprites that the second animation wants.

I could fix this by making the transition happen instantly, but that would make the animation less fluid. I'd just prefer that the first animation stops triggering events altogether to let the second animation's events take precedence.

I don't care if the solution is rather roundabout, it's just that I've been wracking my brain for a while over this. Some new input could make me spring some new ideas.

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

2 Replies

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

Answer by Pyrian · Apr 13, 2014 at 04:39 PM

If roundabout is okay, just trigger a script at the beginning of each animation that sets a flag, which you use to decide which script calls to honor or ignore, inside those scripts themselves.

Comment
Add comment · Show 6 · 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 Dengar · Apr 13, 2014 at 05:07 PM 0
Share

@Pyrian That sounds like something that could work in theory. But in an animation that loops, wouldn't that flag get set each time? At least, I haven't found away to enter a script into an animation on startup outside of the timeline loop, so to speak. Is there a way to do that? Again, roundabout is fine.

avatar image Pyrian · Apr 13, 2014 at 07:50 PM 0
Share

Well, if the flag is always be referring to the most recent animation that begun, then setting it each loop is still correct and not enough processor power to worry about. If you're doing more than setting a flag and you don't want it to repeat in loops, just check said flag, and only do your process if you're actually changing it.

If there's an event call upon an animation transition beginning, I couldn't find it.

avatar image Dengar · Apr 14, 2014 at 02:39 PM 0
Share

Well, the thing is, during a transition, the events for both animations will get fired. So the flag would keep swapping between the two.

That being said, a solution has been for$$anonymous$$g in the back of my $$anonymous$$d. It involves changing the function calls in the animation events to send an AnimationEvent object. If I'm right about my hunch, I can use that to identify the animation state that is sending the object. Then I can easily rig the called method to only do something when the call comes from either the animation that's currently running, or the animation that is being transitioned to.

avatar image Pyrian · Apr 14, 2014 at 03:16 PM 0
Share

$$anonymous$$aybe you should use IsInTransition, possibly combined with GetAnimatorTransitionInfo and its nameHash, to make absolutely sure whether you should run your script given the current transition state. That should be bulletproof, I think.

avatar image Dengar · Apr 15, 2014 at 06:31 PM 0
Share

For some reason, the AnimationEvent.animationState property gives me a NullReferenceException error. I am not sure why it does that. I mean, I -could- just add a tag to the String parameter and identify the animation that sends the object that way, but that's really no fun. :(

Show more comments
avatar image
4

Answer by Mr-Jun · Dec 12, 2018 at 01:08 AM

Seems you can set the Animator fireEvents attribute manually.

  GetComponent<Animator>().fireEvents = false;



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

23 People are following this question.

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

Related Questions

Customizable characters with sprites in 2d 0 Answers

Root motion lost in transitions 1 Answer

Abrupt change of position between animation transition 2 Answers

Animated Overlay Armor Sprite 1 Answer

How to create animated "sprites" in a 3D environment 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