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
0
Question by Ramphic · Nov 02, 2017 at 09:14 AM · animationanimator controlleranimationevent

Transform Of GameObject getting changed incorrectly after updating RuntimeAnimatorController

A gameObject has NavMeshAgent and Animator component.

I am changing runTimeAnimatorController of Animator component in a function called 'changeAnimatorController' at run time in the following way:

 RuntimeAnimatorController newAnimController = Resources.Load("AnimControllers/WalkAnimatorController") as RuntimeAnimatorController;
 
 void changeAnimatorController()
 {
       this.gameObject.GetComponent<Animator>().runtimeAnimatorController = newAnimController  ;
 }

Now calling this function is working differently when called in the following two different ways:

  1. If I call the function 'changeAnimatorController' directly from script, my Animator controller is getting updated to the new one, but gameObject's position is getting changed to the gameObject's original position present before the game play starts, and getting updated to the correct position in next frame. For example, before the game play starts, my gameObject is at position (0,0,0). After game starts, at a particular time my gameObject moved to (10,0,0) through animation. Now if I call the function 'changeAnimatorController', gameObject's position is getting changed to (0,0,0) , but again getting updated to (10,0,0) in the next frame.

  2. If I call the function 'changeAnimatorController' from an event of animation clip present in current animator controller (which I am going to replace), gameObject's position is getting changed to the gameObject's original position present before the game play starts, and never getting updated to the correct value in any frame.

For example, before the game play starts, my gameObject is at position (0,0,0). After game starts, at a particular time my gameObject moved to (10,0,0) through animation. Now if I call the function 'changeAnimatorController' from an event of animation clip, gameObject's position is getting changed to (0,0,0) and never getting back to (10,0,0). But to my surprise here, if baseOffset of gameObject's navMeshAgent is updated immediately to some value after updating RunTimeAnimatorController in the following way, it's position is getting updated to the correct value ((10,0,0) in the above example).

 void changeAnimatorController()
 {
           this.gameObject.GetComponent<Animator>().runtimeAnimatorController = newAnimController  ;
           this.gameObject.GetComponent<NavMeshAgent>().baseOffset = requiredBaseOffset;
 }

In all the above cases, after changing RunTimeAnimatorController of gameObject, rotation of gameObject is getting changed to gameObject's original rotation present before game play starts. For example, before the game play starts, my gameObject's rotation is (0,0,0). After game starts, at a particular time my gameObject's rotation is (120,0,0) through animating. Now if I call the function 'changeAnimatorController', gameObject's rotation is getting changed to (0,0,0) and never getting back to (120,0,0).

Any idea why it's happening this way? Why calling the function 'changeAnimatorController' from different places works differently? What's the correct way to change runTimeAnimatorController of Animator at run time?

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

0 Replies

· Add your reply
  • Sort: 

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

187 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

Related Questions

How to prevent an animation from triggering more than on due to fast clicking? 2 Answers

StateMachineBehaviour is working weird with AnimationClip.AddEvent 0 Answers

AnimationEvent has no receiver, but there is no AnimationEvent 1 Answer

How do i add an AnimationEvent to an animation of a single instance with script? 0 Answers

Animation Event is won't be called 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