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 Alverik · Sep 11, 2016 at 02:51 PM · c#editor-scriptingruntimeawake

Animation selector Editor. Losing data at runtime. Awake() returns Debug.Log several times.

Hey, I'm trying to make an editor which allows me to select any of the animations in an object using a popup dropdown. I just slot an object. And it captures the name of the object to find at runtime plus the whole list of animations in the animator/object. The actual popup works, it does show me the animation clips in the object in the inspector, but when I hit play something strange happens. I've setup some debug.logs in Awake() which show me the name to use for searching the object but it appears 17 times. the first time it gives me the name properly, but the next 16 times it returns the name empty (which causes the object's search to be always null).

here is the editor code:

 //checking animations -- s means Source/SourceScript
 
             s.TempObject = (GameObject)EditorGUILayout.ObjectField("Object to animate:", s.TempObject, typeof(GameObject), true);
             EditorGUILayout.Space();
             if (s.TempObject == null)
             {
                 EditorGUILayout.LabelField("There's no object to animate...");
                 return;
             }
             s.ObjectName = s.TempObject.name;
             //get the animations in the object
             AnimationClip[] animations = AnimationUtility.GetAnimationClips(s.TempObject);
             //get the clips names into a list
             string[] nameArray = new string[animations.Length];
             int i = 0;
             foreach (AnimationClip clip in animations)
             {
                 nameArray[i] = clip.name;
                 i++;
             }
 
             int index = 0;
             index = EditorGUILayout.Popup("Select an animation to play: ", index, nameArray, EditorStyles.popup);
             //return the name of the selected animation clip
             s.ClipName = nameArray[index];


This is the regular script's code that has to do with this (there's more but it doesn't have anything to do with this- script functions like a hotspot):

 //Animation variables
             public string ClipName;
             public string ObjectName;
             public Animator MyAnimator;
 
             public GameObject TempObject;
             private GameObject _runtimeObject;
             
             
             //Then inside a protected virtual void awake()

             Debug.Log("name of the object to animate is: "+ObjectName);
 
             //initialize animation variables
             _runtimeObject = GameObject.Find(ObjectName);
             if (_runtimeObject != null)
             {
                 MyAnimator = _runtimeObject.GetComponent<Animator>();
 
                 if (MyAnimator == null)
                 {
                     Debug.Log("The animator is null...");
                 }
             }
             else
             {
                 Debug.Log("object it's null...");
             }

I tried checking if it was because the editor script kept trying to read the object and was overwriting the data. So I put the code inside an if in Unity Editor, but same thing happened. I also tried if (EditorApplication.isPlaying) return; but no difference. And I get the debug.Log with the ObjectName 17 times, even though it's in Awake() (the very first one is always right, the others always return empty...) Any Ideas? I'm kinda running dry of them right now...

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

1 Reply

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

Answer by Alverik · Sep 11, 2016 at 04:34 PM

Never mind, it works. The animation isn't playing for a different reason (the animation I was trying to call for my object was set in the Default slot in mecanim, and even if named the same as the animation it didn't seem to work at all... had to make a separate state with the animation name to get it working). Also, Awake() seemed to be running more than once because I wasn't aware there were other objects in the scene sharing the script (I felt so stupid when I found out)...

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

222 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 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Dynamic editor dll linking? 0 Answers

GetComponent and AddComponent with variables for Collider type 2 Answers

Property Drawer and Inheritance 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