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 Jean-Fabre · Sep 25, 2015 at 04:36 PM · animatorcustom-inspectorstate-machine

StateMachineBehaviour: how to get runtimeAnimatorController from custom inspector

Hi,

I am looking to get the runtimeAnimatorController from a custom inspector of a StateMachineBehaviour, but I fail to find how to get it.

I don't want to get it at runtime, I need to get it during editing.

Any hints will be appreciated :)

Bye,

Jean

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 McGravity · Nov 15, 2015 at 10:29 AM 0
Share

Could this be of any help?

http://forum.unity3d.com/threads/statemachinebehaviours-get-from-editor-script.312123/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jason-RT-Bond · Apr 19, 2020 at 08:57 PM

I know this is ancient but it came up first in my Googling so thought I should add a sort-of solution.

Note that this will get you the AnimatorController (in UnityEditor.Animations), NOT the RuntimeAnimatorController, which presumably only exists at runtime. In my case, I was looking to access the parameters of the animator and this can only be done via the AnimatorController anyway.


Refer to this doc: https://docs.unity3d.com/ScriptReference/Animations.AnimatorController.FindStateMachineBehaviourContext.html

They provide an example of this static call which can get you the StateMachineBehaviourContext, and they access the AnimatorState from that context. But this context also provides the AnimatorController just as easily!


Here is part of my use case, just getting the controller and displaying a pop-up selector which let's you pick one of the parameters.

 using UnityEditor;
 using UnityEditor.Animations;
 using UnityEngine;
 
 [CustomEditor (typeof (SetParameter))]
 public class SetParameterEditor : Editor {
 
     AnimatorController controller;
     int paramIndex;
 
     void OnEnable () {
 
         StateMachineBehaviourContext[] context = AnimatorController.FindStateMachineBehaviourContext (target as StateMachineBehaviour);
         if (context == null || context.Length == 0)
             return;
 
         controller = context[0].animatorController;
     }
 
     public override void OnInspectorGUI () {
 
         if (controller == null)
             return;
 
         string[] paramNames = new string[controller.parameters.Length];
         for (int i = 0; i < paramNames.Length; i++) {
             paramNames[i] = controller.parameters[i].name;
         }
 
         serializedObject.Update ();
 
         paramIndex = EditorGUILayout.Popup ("Parameter", paramIndex, paramNames);
 
 
         serializedObject.ApplyModifiedProperties ();
 }


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

28 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

Related Questions

Transition to multiple states from Entry Node in Unity 5 1 Answer

Mecanim transition retargeting and conditional exit to any state? 0 Answers

Having an Animator play Either/Both/None of two animations 1 Answer

Checking Transitions in Animator 0 Answers

Bool in animator is not changing state 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