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 BogdanDude · Jun 10, 2010 at 09:35 PM · animationframeratesync

Syncing 30FPS animations in Unity to trigger events

Hi!

I'd like to sync some attack animations I made in an animation package, and trigger some events in Unity.

For example, I have this animation running at 30FPS in my animation software: IDLE 10 frames -> MOVE 5 frames -> ATTACK -> IDLE 10 frames

(the character is walking 'in place' for the MOVE part, and it sends out messages to the enemies for the ATTACK part)

The way I did it in Unity was:

IDLE:

yield return new WaitForSeconds(10F/30F);

MOVE:

float t = 5F/30F;
while (t>0)
{
characterController.SimpleMove(direction);
t-=Time.deltaTime;
yield return 0;
}

and then ATTACK and another WaitForSeconds(10F/30F);

I'm not sure I understood correctly how frames and time are related. So am I doing the right thing to sync the animations with the actions perfectly? (even if the game runs at 5FPS or 60FPS)

Thanks a lot!

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
2

Answer by Tetrad · Jun 10, 2010 at 10:00 PM

You probably want to use animation events.

Here's a video describing animation events: http://vimeo.com/11399349 Here's a video telling you how to edit (specifically, copy then edit) imported animations to add animation events: http://vimeo.com/11399550

And here's the documentation: http://unity3d.com/support/documentation/Components/animeditor-AnimationEvents.html

Copying/editing imported animations is a bit of a pain depending on your work flow, so you may consider adding your events programmatically: http://unity3d.com/support/documentation/ScriptReference/AnimationClip.AddEvent.html

Read that carefully, specifically this part:

Note that events added with AddEvent will only persist until play mode is exited of player is quit.

The way we do things is have an animation event setup state that gets called on game start that adds animation events to our clips once and only once. If you add the "same" event multiple times to the same animation clip, it'll fire multiple times (so don't have your enemy class add events to their clips every time you spawn an enemy, for example).

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 BogdanDude · Jun 11, 2010 at 10:28 AM 0
Share

Thanks for your answer, Tetrad. Those animation events could prove really useful. I forgot to mention I'm using Unity iPhone 1.7, so I don't have access to those animation features in Unity.

So regarding my method, do you think the animations and the events would sync perfectly?

Thanks!

avatar image Tetrad · Jun 11, 2010 at 05:30 PM 1
Share

You don't have access to the fancy animation windows, but you can still add animation clip events procedurally, I think.

avatar image
0

Answer by Mike 3 · Jun 25, 2010 at 01:31 AM

The code looks reasonable enough to me

Animation frames are done exactly how you seem to be thinking - they're just run at x frames a second, completely independent of the game FPS

Re. Animation events - they'll work except for the moving part of your code, you'd still need to do that via a coroutine or some form of update

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

No one has followed this question yet.

Related Questions

Allow Unity to render as fast as possible? 0 Answers

how to do an action at a certain point of an animation in mecanim 1 Answer

syncronize long animation & sound 1 Answer

Sync animaor of child prefab 0 Answers

How do you sync animations in Photon (free version)?,How do you sync animations in Photon(free version)? 0 Answers


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