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 Screenhog · Oct 29, 2012 at 07:43 PM · animationjavascriptlayerblendingweight

What am I not getting about animation weight blending?

I've been having difficulty getting animation blending to work, so I've created a simple example. Can someone please explain what I'm doing wrong?

Assume there are two animations on a character... "walk" and "zombie". (Why zombie? Why not zombie? It's Halloween.)

Here is code:

 function Start () {
     animation["walk"].layer = 2;
     animation["walk"].weight = 1.0;
     animation["zombie"].layer = 3;
     animation["zombie"].weight = 0.5;
     
     animation.Play("walk");
     animation.Play("zombie");
 }

By my understanding, this should play zombie at half weight and walk at half weight, but instead, it plays zombie at full weight. Why?

EDIT: To further describe, let's say I change my code to this:

 function Start () {
     animation["walk"].layer = 2;
     animation["walk"].weight = 0.5;
     animation["zombie"].layer = 2;
     animation["zombie"].weight = 0.5;
         
     animation.Play("walk");
     animation.Play("zombie");
 }
 

Even when I do that, it still plays the "zombie" animation at full weight instead of evenly distributing them. Does anyone know why that might be?

EDIT #2: Changing the order of the animations makes a difference. If the "walk" animation is set to play after the "zombie" animation, the "walk" animation will play instead, at 100% weight.

Still, this doesn't solve the overall problem of making them blend 50-50.

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 Fixe · May 04, 2014 at 09:08 PM 0
Share

To solve the problem of gettin 50-50, you need to set top layer to 50% and bottom layer to 100% (it will get the 100% of the 50%, like stated in the wiki page)

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Oct 29, 2012 at 08:06 PM

Each animation layer is handled seperately. A higher layer number has a higher priority. The highest layer is "served" first. When it doesn't use all weights, the lower layers get their part of the remaining weight.

See the blending weight page.

Also the blend weights are always normalized. When you have two animations on the same layer, one with 1.0 and one with 0.5, the first one will get 0.66666 and the second 0.33333. In this case this layer eats up 100% of the weight.

Here's another example:

 Animation  layer   blendweight   resulting weight
 anim1      1       0.2           0.2             ---> remaining weight
 anim2      1       0.3           0.3             --->   == 0.5
 anim3      0       4 (== 0.4)    0.2 (== 0.5*0.4)
 anim4      0       6 (== 0.6)    0.3 (== 0.5*0.6)


Comment
Add comment · Show 7 · 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 Screenhog · Oct 29, 2012 at 08:57 PM 0
Share

$$anonymous$$y highest layer is layer 3, and it should take half of the weight. The other layer is 2, and it should take the remaining half, right? So why would the zombie animation play at full if they should be evenly distributed?

And even if I put both animations on the same layer, and with the same weight of 0.5, the animations still aren't blended. Is there a setting I'm missing?

avatar image Bunny83 · Oct 30, 2012 at 12:03 AM 2
Share

Like you figured out, Animation.Play does two thinge (or three):

  • It enables the AnimationState and rewinds it when it's not playing at the moment.

  • It sets the blendweight to 1.0

  • It eventually stops other animations depending on the second parameter (Play$$anonymous$$ode).

CrossFade does almost the same, but it keeps the old animation playing and "lerps" the blendweights over time.

You don't need to use the Play or CrossFade function at all. When you want full control of your animations, just:

  • enable your desired animation state(s).

  • Set the weights.

  • $$anonymous$$aybe reset the time.

See the AnimationState class for more information.

avatar image Screenhog · Oct 30, 2012 at 12:05 AM 1
Share

THIS! THIS IS WHAT I NEEDED!

I wish I could have had the above paragraphs about two years ago. It would have saved me so much confusion.

avatar image Bunny83 · Oct 30, 2012 at 12:08 AM 0
Share

To answer your two edits in your question:

Edit1: This doesn't work because both animations are on the same layer and the default parameter for Play() is Play$$anonymous$$ode.StopSameLayer. When you use the Play function, only one animation per layer is allowed.

Edit2: Sure, when you change the order the other animation will play ins$$anonymous$$d. Only the "last call" will take effect.

avatar image Screenhog · Oct 30, 2012 at 12:22 AM 0
Share

The moment you said "It sets the blendweight to 1.0" it all made sense, but thanks for clarifying. That's what I needed to know in the docs. (Animation.Play() does not seem to mention that little detail.)

Show more comments
avatar image
0

Answer by whydoidoit · Oct 29, 2012 at 07:59 PM

Higher layers get the weight first - so it get a much higher proportion. Putting them on the same layer with the same weight would give you half of each. The weights are kind of added up with to get the final proportion. Basically all of it goes to the higher layer.

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
avatar image
0

Answer by Screenhog · Oct 29, 2012 at 11:02 PM

Finally found a fix. I had to set the weight of the animation AFTER playing it.

 function Start () {
     animation["walk"].layer = 2;
     animation["zombie"].layer = 3;
     
     animation.Play("walk");
     animation["walk"].weight = 1.0;
     animation.Play("zombie");
     animation["zombie"].weight = 0.5;
 }

Unfortunately, I guess this means that I'll have to set the weight manually each time. But at least it now makes sense.

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 whydoidoit · Oct 30, 2012 at 12:02 AM 0
Share

Ugh - of course - animation.Play sets the weight...

avatar image
0

Answer by OLGV · Sep 10, 2013 at 02:41 PM

I have a question on this... if I have 20 animation files (rotate, move, etc) and the 21th that animates just the intensity (spot light), how could you make layer 1 applying for any animation file on the object... so I can turn them all on and off no matter of what other motion animation is happening around...

I am trying to avoid making a separate scripts for each animation file..

would something like this work?

 function Start () {
     animation["walk, walk2, walk3, walk4"].layer = 2;
     animation["zombie"].layer = 3;
  
     animation.Play("walk, walk2, walk3, walk4");
     animation["walk, walk2, walk3, walk4"].weight = 1.0;
     animation.Play("zombie");
     animation["zombie"].weight = 0.5;
 }

or other way of not listing all the animation files..

thanks

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

13 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

Related Questions

Play 2 animations at once 4 Answers

Animation layers: Am i limited to only one layer per animation? 0 Answers

animate pose, blend movement animation 0 Answers

Animation: Impact of combining the use of Layer, CrossFade, and Weight 2 Answers

Bug in Animator layer blending ? 4 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