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
3
Question by MLM · Jan 09, 2014 at 08:44 PM · animationmovementmecanimik

Mixing Unity Mecanim and Scripted Bones/States

The problem is that when the Animator component is enabled, it stops any bone movement/rotation in script. Even if you mask out the area where the bone you want to modify is, the animator still impedes.

Version: Unity 4.3.1f1

I noticed that if I enable Animate Physics on the Animator component that I am able to edit the bone rotations but the pose seems to skew the movement on the ground but I think this is because it runs Mecanim in FixedUpdate().

Modifying the bone in the LateUpdate() loop works but if down the line I need something to run after, then I would be almost out of luck. Is this still the only means of working around this issue?

Update 2014-1-20: I just stumbled upon the Optimize Game Objects option under the rig section of your model. This is a great feature to save memory and probably CPU but there is NO way to mix script bones with Mecanim when you enable this feature. Even when you use the Expose Transform option, modifying those transforms has absolutely no effect. I assume this is because it is mainly thought of as a read-only type of nodes to attach to or spawn things.

Previous Update: I just noticed the following quote from this article:

"Update 5 Dec 2013: Today I noticed that Unity 4.3 has added the Animator.Update() which could be used to implement the ragdoll to animation blend more elegantly without the LateUpdate() trickery. I'll have to update this example when I have time."

I do not see Animator.Update() in the script reference and I am not sure how to hook/use this loop. Is this new function the way to go and how can it be used?

Edit: It seems that since Animator.Update() is not a virtual method that you can not override it and they made Animator a sealed type which prevents inheritance (so you can't hide and extend the method).

The main question of this section is: How do I mix Mecanim with scripts for some of the bones?


I know there is a `Animator.SetLookAtPosition` (and Animator.SetLookAtWeight) methods but rather than an IK type look method, I have a head look script (which you can see in this question) that responds to the mouse.

I can think of a workaround where I make a blend tree with parameter for head rotation that blends left, right, up, down head animations and then adjust the parameter in the head look script. But this seems like a lot of work for simple stuff and might be a problem with the transition time (lagging behind mouse).

I really like the Mecanim system to use the IK system for holding a weapon and the blending of animations but if there are no proper setups then what kind of best alternatives are there?

Possible Alternatives (haven't used):

IK:

  • Inverse Kinematics by Dogzer - includes elbow targeting (Mecanim currently does not have this feature in Unity 4.3.1f1)

Animation Blending/Transitioning:

  • I can't find any


Here are some other links talking about this issue:

  • Mecanim and script bone controlled

  • How to combine mecanim and script based bone movement/animations?

  • Override mecanim animation with manual bone rotation

  • Player animations & Unity

  • Mecanim - Control torso through script?

  • Mecanim: modifying animation in script when animate physics in on, impossible ?

  • Are bone transforms in LateUpdate the transforms for the next or previous frame?

  • Exact order of operations to render a frame (character animation problem)

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 HappyMoo · Jan 20, 2014 at 10:52 PM 0
Share

If you need something later than LateUpdate, there is OnPreRender and then there is Script Execution Order for even more Control.

The way it's supposed to be is of course by using OnAnimatorI$$anonymous$$, but I$$anonymous$$ is pro only - have you tried if the method still gets called in Free? http://docs.unity3d.com/Documentation/$$anonymous$$anual/Inverse$$anonymous$$inematics.html

Upvote for Asking a question how you're supposed to ask questions here ins$$anonymous$$d of "write code for me"

avatar image MLM · Feb 02, 2014 at 06:32 AM 0
Share

@Happy$$anonymous$$oo Sorry, I have not tried OnAnimatorI$$anonymous$$() in free as they make it hard to switch back and forth from pro to free. That function is called before I$$anonymous$$ is updated by $$anonymous$$ecanim so it doesn't help with modifying bones after everything is said and done.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by duck · Jan 29, 2014 at 08:32 PM

Yes you are correct about "Animate Physics" checkbox - it simply makes Mecanim update in sync with the physics timestep instead of the game's framerate, so adjusting bones in LateUpdate when using "Animate Physics" will give weird unpredictable syncing problems depending on the framerate the project is running at.

As you've found, you can modify the bones successfully in LateUpdate() when Animate Physics is unchecked, and if you need further scripts to be executed after these particular LateUpdate scripts, you can use Unity's Script Execution Order controls to ensure other scripts with LateUpdate functions occur afterwards.

Animator.Update() allows you to manually update the animator according to whatever timestep you pass. This is useful when you want control over the 'deltaTime' that the animator is using rather than letting it play back according to the current timeScale.

You can use this for timescale-independent animation. Here's an example of an explosion and physics playing with the timescale set to 0.03, so it's super-slow motion, and I'm manually calling Animator.Update(t) on the controller for the landing gear of the aeroplane, where 't' is calculated using Time.realtimeSinceStartup so the wheels are extending and retracting at a normal speed, within the slow-motion scene.

Slightly weird demo, I know - but I happened to have this project open at the time a few days ago when someone else asked about Animator.Update() :)

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 MLM · Feb 02, 2014 at 06:23 AM 0
Share

@duck Thanks for the response! Do you know of any solution for the problem proposed in the "Update 2014-1-20" section of the main post about the Optimize Game Objects setting?

I moved onto networking waiting for this issue so I am not as acquainted/"in the trenches" as I was days/weeks ago with this topic. Hopefully this will all come together when I get back to it.

The Animator.Update() demo and explanation was awesome!

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

20 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Possible to play single clips using Mecanim? 0 Answers

Animate arm to grab object with IK/Mecanim 0 Answers

For easy simple games, you can do without using Mecanim and instead just do it through Scripts? 1 Answer

Character Animation Question (Bear Force One) 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