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 Polymo · Sep 20, 2013 at 12:28 PM · mecanimlayerstate

Mecanim get current Layer

Hi, maybe i just have the wrong approach, but i'm looking for a way to get the current layer in Mecanim.
I dont want to check on all clips contained in the layer, as in AnimatorStateInfo.nameHash //"LayerName.ClipName" (Animator.stringToHash("OnlyLayerName") doesnt trigger)

I have all characters emotes in a layer (set to override) and triggered by an int.
Now i want to check if it's currently inside the emote layer to reset the emote-int to 0
(and i do not want to check if each of the emotes is currently playing, as this seems very inefficient (around 15 emotes) )

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 Polymo · Sep 21, 2013 at 08:41 PM 0
Share

ping . .

avatar image Polymo · Sep 26, 2013 at 05:42 AM 0
Share

so, i guess it's not possible directly.

2 Replies

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

Answer by TonyLi · Sep 26, 2013 at 01:45 PM

In a general sense, there's no such thing as a "current layer." Every layer is active with a weight that determines its influence on the final animation. Of course, override also influences the final animation. As an optimization, Mecanim doesn't evaluate layers with a weight of 0.

If you only increase your emote layer above 0 when you're playing an emote, then you can call GetLayerWeight().

If your emote layer's weight is always 1, then you probably have a null state in the layer. Just check what state you're in, using GetCurrentAnimatorStateInfo(). This is basically what the example scripts do in Update().

You could also use a coroutine that sets emote-int back to 0 after, say, 0.1 seconds. Start the coroutine in the same code block where you set the emote-int.

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 Polymo · Sep 27, 2013 at 06:11 AM 0
Share

Hey, thank you. Thats a good idea. Checking for 'not nullstate' is indeed a working solution.

avatar image
1

Answer by grasmann · Oct 20, 2015 at 12:00 PM

I created this extension to get the dominant layer.

 using UnityEngine;
 
 public static class Extensions {
 
     public static int GetDominantLayer(this Animator Animator) {
         int dominant_index = 0;
         float dominant_weight = 0f;
         float weight = 0f;
         for (int index = 0; index < Animator.layerCount; index++) {
             weight = Animator.GetLayerWeight(index);
             if (weight > dominant_weight) {
                 dominant_weight = weight;
                 dominant_index = index;
             }
         }
         return dominant_index;
     }
 
 }

Basically it iterates through all layers in the animator and searches for the one with the highest weight.

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

18 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

Related Questions

Mecanim - How to figure out the State and layerIndex that triggered Animation Clip Event? 0 Answers

SetAnimationClip on mecanim State using script 0 Answers

Mecanim animation layers with a body mask kills the base animation? 1 Answer

How to get fileID information so i can just edit Mecanim Animator through script? 2 Answers

Macanim Mouse Buttons interaction c# 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