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
1
Question by Tom_JK_ · Mar 11, 2021 at 10:50 PM · animationscripting problemanimatoranimator controllerdesign

How to properly detect the end time of an Animation which wait for the end of the previous one ?

Hello everyone,
I already tried to post a similar question, but I had no answer so far, and I'm quite sure it's because it is a way too complex for what it is.
So I'll try to make very simpler and clearer.

Project : The main goal is to create a system where a NPC have some tasks, and each one of them have 1/ a location (the NPC will walk there then continue) 2/ a specific animation (launched after the destination is reached). I want to synchronize the animation and the action : launch a specific method once the animation is ended. And finally, I want the NPC to wait the end of the "Walking" animation before launching the animation of the task.

Problem : I'm looking for a good design for this. I've been on it for a long time now, and I just can't find something even though it seems like a very basic problem. I tried to lock the completion of the task with this chunck of code, but for some reasons it don't fit perfectly with the end of an animation...

 {
      float currentAnimLenght = _npcAnimator.GetCurrentAnimatorStateInfo(0).length;
      float normalizedTime = _npcAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
      float normalizedTimeInCurrentLoop = normalizedTime - Mathf.Floor(normalizedTime);
 
      // Wait that the moving animation is ended
      yield return new WaitForSeconds(currentAnimLenght - normalizedTimeInCurrentLoop);
 
      // Set Trigger to launch the task animation, then wait until its end
      _npcAnimator.SetTrigger(name);
      yield return new WaitForSeconds(_animClipLenght[name]);
 
      // This boolean prevent the NPC to do next tasks until this one is done
      isAnimLaunched = false;
      yield return null;
  }



Can you please help me ? Do you have any "classic" method, a previous topic or a YT video that shows a great way of doing this ?

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 Casiell · Mar 12, 2021 at 02:15 PM 1
Share

I will just preface this by saying that I absolutely despise this way of doing stuff with animation, but sometimes there is just no choice.

You can add events to animations! Link below is for 2020.3, but they've been around for ages, so don't worry if you work on older version. You won't have all those fancy options tho, only method name, no parameters, but it should be good enough for your use case.

Documentation link

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ARobbins67 · Mar 12, 2021 at 09:57 PM

Hi,

Have you looked into animation events? They basically allow you to call some code at a certain frame in the animation, so you could put an event at the animation frame where you want the action to happen. I put a link below for more info. Hope this helps!

https://docs.unity3d.com/Manual/script-AnimationWindowEvent.html

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

290 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 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 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 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 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 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 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 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 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 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 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 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 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

How to create animations that can be edited with scripts in runtime? 1 Answer

Animator and Scripting problems. Help !! 1 Answer

Character Animator controller/movement 1 Answer

Is there a new retargetting system for the animation in 5.5? 1 Answer

2 problems with new animation / animator,2 problems with animation 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