Jump to content

Getting the animation name... WHUT?


Recommended Posts

Ok, I'm not stupid.  I have done this a bunch of times.  But now, this is giving me results that... I frankly don't understand.

            foreach (Animation anim in part.GetComponentsInChildren<Animation>()) 
            {
                Debug.Log("Found animation name: " + anim.name);
            }

Ok, pretty simple right?  Find me all the animations on the part and tell me what the name of the animation is.  Or so you'd think.

If the animation is somewhere in the hierarchy of the part, it's coming back with anim.name = the transform name (the one at the top of the inspector) and not the actual animation name.

If the animation exists on the root GameObject, it's coming back with anim.name = the MODEL NAME from part tools.  WHUT???

So somehow, thinking I've had a case of the stupids and all my other code that grabs animations is now junk, I decided to try this:

            foreach (Animation anim in part.FindModelComponents<Animation>()) 
            {
                Debug.Log("Found animation name: " + anim.name);
            }

And I'm getting the same result.  

Please explain as this makes verifying that I'm loading the correct animation by name rather difficult.

Now here's where it gets really stupid.

If I do this:

            List<Animation> list = new List<Animation>(base.part.FindModelComponents<Animation>());
            int i = 0;
            int count = list.Count;
            while (i < count)
            {
                Animation animation = list[i];
                if (animation[animationName] != null)
                {
                    partAnimation = animation;
                }
                i++;
            }

or some variation thereof, and tell it to assign the animation it finds to partAnimation by name (animationName), it's happy.  It passes the correct animation over to partAnimation even though the name is wrong.  I.E. animationName = lightsAnimation  and animation.name = Model

Edited by Fengist
Link to comment
Share on other sites

15 hours ago, Fengist said:

Please explain as this makes verifying that I'm loading the correct animation by name rather difficult.

https://docs.unity3d.com/ScriptReference/Animation.html : "name  The name of the object."

https://docs.unity3d.com/ScriptReference/Object-name.html : "Components share the same name with the game object and all attached components."

You are not checking the animation name.

What you want is https://docs.unity3d.com/ScriptReference/Animation.Index_operator.html

Or even more simply Animation FindModelAnimator(string clipName) Animation[] FindModelAnimators(string clipName)

Link to comment
Share on other sites

4 hours ago, sarbian said:

https://docs.unity3d.com/ScriptReference/Animation.html : "name  The name of the object."

https://docs.unity3d.com/ScriptReference/Object-name.html : "Components share the same name with the game object and all attached components."

You are not checking the animation name.

What you want is https://docs.unity3d.com/ScriptReference/Animation.Index_operator.html

Or even more simply Animation FindModelAnimator(string clipName) Animation[] FindModelAnimators(string clipName)

I guess I'm looking at it wrong.  I assumed that the name of the animation component that I dropped into Unity would take on the name of the animation assigned to it.  Yes, I used FindModelAnimator(s) to locate the animations it works fine, it just seems strange that the actual animation component would take on the object name.

Thanks 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...