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 testure · Jul 02, 2011 at 11:54 PM · animationtimeframeprecisioncurrent

animation["name"].time is always zero?

I'm trying to set up the timing of a melee attack so that it calls a damage event at the right moment- but I'm not able to get the current time of the animation clip to work correctly.

From everything I've read, animation["name"].time should return the time in seconds that a clip is currently at- if I just Debug.Log this value, it remains at zero even though the animation is playing.

Anybody have any experience with this, and why time would always be zero?

An extremely simplified version of my code looks something like this:

 // note that this code is part of a coroutine that loops repeatedly while the player is attacking- 
 // so while it looks weird for the debug to be ABOVE the call to animate, rest assured
 // that it is actually animating when the Debug.Log is called.
 
     Debug.Log(behaviorController.meshRef.animation["attack2"].time);
 
     if(currentTime < nextAttackTime)
         return;
 
     behaviorController.meshRef.animation.CrossFadeQueued("attack2", .4f, QueueMode.PlayNow);
     currentTime = Time.time;
     nextAttackTime = Time.time + 2f;

Comment
Add comment · Show 1
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 testure · Jul 03, 2011 at 01:21 AM 0
Share

Okay due to some confusion on the code I posted- there is an interval check in my code that prevents the animation from queueing every frame. It's part of a much larger logic sequence that I didn't have time to parse out for my post.

The animation is definitely playing, and is not queued every frame- it happens every couple of seconds (roughly the length of the animation)

3 Replies

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

Answer by testure · Jul 03, 2011 at 03:03 AM

Thanks for the responses guys- I figured out the problem through trial and error. It turns out, CrossFadeQueued does not seem to update the AnimationState ever, so time is always going to be zero. I tested it out in an isolated environment and only fired CrossFadeQueued once- and time never moved past zero.

So I added a bit more logic to give me the same functionality that I was using CrossFadeQueued for, changed it to CrossFade, and now animation["name"].time correctly outputs the correct timing for the animation.

Comment
Add comment · Show 2 · 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 Bunny83 · Jul 04, 2011 at 12:22 AM 1
Share

Did you even read my answer or the docs on CrossFadeQueued carefully? CrossFadeQueued returns the AnimationState it has duplicated. Accessing the original AnimationState would of course give you not the right values.

avatar image testure · Jul 04, 2011 at 12:31 AM 0
Share

Right, and thus it won't work for my purposes.

avatar image
1

Answer by Waz · Jul 03, 2011 at 01:03 AM

I'm not resting assured - from the docs:

If queue is QueueMode.PlayNow this animation will start playing immediately on a duplicated animation state

So you are debugging the animation state before it is duplicated. We'd have to see more of the loop to understand what you're trying to do, but certainly that's why your Debug is not showing anything.

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 testure · Jul 03, 2011 at 01:43 AM 0
Share

Yeah, sorry- that's my fault for not submitting enough code. I was in a bit of a hurry when I posted it- but I've gone through and made some notations.

avatar image
1

Answer by Bunny83 · Jul 03, 2011 at 01:14 AM

The problem is that Animation.CrossFadeQueued is a very special function and it shouldn't be called each frame! Unity will actually clone the animation (so there's another copy of the same animation) and save this call internally. When the current animation is finished it will play the clone automatically. It is cloned so that it can crossfade even to itself. Is there any reason why you use CrossFadeQueued?

CrossFadeQueued returns the duplicated AnimationState but as the docs say, be careful, the Animation state will delete itself after the animation has finished.

I would suggest to use AnimationEvents for your "timing".

Comment
Add comment · Show 3 · 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 testure · Jul 03, 2011 at 01:46 AM 0
Share

I don't have much experience with AnimationEvents, I'll defintely give them a good investigation. Thanks for the tip, and the reply.

avatar image testure · Jul 03, 2011 at 01:55 AM 0
Share

Looking into AnimationEvents- all of my animation clips are read only. This is a skinned mesh imported via FBX if that matters... Is that normal? All of the examples in the unity docs are animating values such as transforms and public inspector variables... are you sure Animation Events can be applied to a skinned mesh?

avatar image Bunny83 · Jul 04, 2011 at 12:34 AM 0
Share

An animation is still an animation, no matter what you animate. Actually imported animations also just animate the transforms of the bones, nothing more. The animation has no relation to the skinned mesh. Only the skinnedmesh have the link the the bones so the model gets animated because the bones are animated.

You are right, Unity have problems with imported animations because they are read-only. In our project i wrote a small script that extracts the animations as .anim files so they are seperate animationclips that can even be edited in Unity. But it's easier to add the animationevents via scripting. With AnimationClip.AddEvent you can add events at runtime but have in $$anonymous$$d that AnimationClips are shared between all Animation components so adding an event multiple times will fire it multiple times. $$anonymous$$ake sure you add every event only once game-wide

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Time Delay Animation 1 Answer

2D game animation is running 1 Answer

timer that can be reset 1 Answer

Can I make animations snap to a frame? 1 Answer

Clamp animation to a certain amount of time? 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