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 /
This question was closed Nov 27, 2017 at 10:14 PM by dwyffq for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by dwyffq · Sep 02, 2017 at 06:40 PM · animation2druntimeanimator controllerframe

How to play only one frame of animation using and changing RuntimeAnimatorController

Hello! I want to play only one frame of an animation clip inside a RuntimeAnimatorController that is an AnimatorOverrideController. I'm using 2d.

I get no errors on console but the sprite does not change. I used a prefab and assigned the RuntimeAnimatorControllers.

Edit: I need to use the others animator controllers to change the animation too.

My current code is:

 public class Sample : MonoBehaviour 
 {
     public RuntimeAnimatorController animator2;
     public RuntimeAnimatorController animator3;
     public float timeBetweenChanges = 0.3f;
     
     private Animator _animator;
     
     public enum MyAnimatorTypes
     {
         animator2 = 0,
         animator3 = 1
     }
     
     void Start()
     {    
         _animator = (Animator)GetComponent(typeof(Animator));
     }
 
     IEnumerator _crChangeType()
     {
         yield return new WaitForSeconds(timeBetweenChanges);
 
         _ChangeType();
 
         StartCoroutine(_crChangeType());
     }
     
     private void _ChangeType() 
     {
         MyAnimatorTypes newType = MyAnimatorTypes.animator2;
         
         switch (newType)
         {
             case MyAnimatorTypes.animator2:
                 _animator.runtimeAnimatorController = animator2;
                 break;
             case MyAnimatorTypes.animator3:
                 _animator.runtimeAnimatorController = animator2;
                 break;
         }
         
         AnimatorStateInfo asi = _animator.GetCurrentAnimatorStateInfo(0);
         
         _animator.Play(asi.shortNameHash, 0, 0f);
     }
 }
Comment
Add comment · Show 2
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 Cherno · Sep 02, 2017 at 11:12 PM 0
Share

I'dv try setting a bool to true after playing the animation, then in the same Update function (Update, FixedUpdate or LateUpdate) if the bool is set to true, stop the animation or play anohter one (and set the bool to false again). This should theoretically play the animation for one frame, which is the time from one of the Update functions to the next.

avatar image dwyffq Cherno · Sep 03, 2017 at 01:13 AM 0
Share

Thank you! But the current code does not play the animation yet... I don't know why...

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by dwyffq · Nov 22, 2017 at 04:50 PM

Sorry. This part of code is working. I had more code and forgot to set some things in inspector

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

Follow this Question

Answers Answers and Comments

216 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

Related Questions

How do I construct my animation state machine this way? 0 Answers

My Anima 2D's flipped animations are bugging out. 0 Answers

Animator Controller 2D RPG Best Practices 0 Answers

Beginner using the animation controller to get a sprite walking left and right..Need some help going from here 0 Answers

animations as transitions to other animations 2d 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