Check you don’t have any compiler errors in your project, they need to be fixed first. Otherwise, check that you don’t have a custom editor for your type.
Also that’s some very claustrophobic code.
And I’ll also note the UnityEditor stuff can’t be used in a built project.
It was a bug built up through usage… if I clicked on debug mode for inspector… the contents of the Arrays and Lists would show up. If I then unclicked/returned to normal mode, the list and array content would continue to show… but only AFTER I’d done this initial reveal through the use of the debug mode.
A restart of Unity and I no longer need to trigger debug mode of the inspector for the contents of the array and list (elements) to be shown…
Yes, claustrophobic code. I don’t like wide open spaces, only eating the cows that graze on them.
You’ll want to make a custom editor for your type, use that to draw the default inspector and then add a button that does the task on the editor side of things.
So we can cut your monobehaviour down to this:
using UnityEngine;
public class AnimControlName : MonoBehaviour
{
#region Inspector Fields
[SerializeField]
private Animation _anim;
public AnimationClip[] _clips;
[SerializeField]
private int clipToRun;
public string[] _clipNames;
#endregion
#region Properties
public Animation Anim => _anim;
public AnimationClip[] Clips => _clips;
public int ClipCount => _anim.GetClipCount();
#endregion
}
(I removed the clip count component as it could just be a property)
And then we make a custom inspector:
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(AnimControlName))]
public class AnimControlNameEditor : Editor
{
private AnimControlName animControlName;
private void OnEnable()
{
animControlName = (AnimControlName)this.target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Find Clip Names"))
{
animControlName._clips = AnimationUtility.GetAnimationClips(animControlName.gameObject);
animControlName._clips = new AnimationClip[animControlName.ClipCount];
for (int i = 0; i < animControlName._clips.Length; i++)
{
animControlName._clipNames[i] = animControlName._clips[i].name;
}
EditorUtility.SetDirty(target);
}
}
}
#endif
Which gives us this:
Didn’t actually test if it works as I don’t have random animations on hand to test it with. But you should get the idea. In practice you’d also use SerializedProperty’s to adjust the values of the component rather than just making them public, but that can be your homework.
Sorry, how does this solve the problem of UnityEditor features (like AnimationUtility) only being available in build being the limitation on getting at the animation clips in their array? As far as I can tell, this still wouldn’t work in a build.
Perhaps I wasn’t clear in the question. It wasn’t how to avoid this usage of an Editor feature being in a Build, it’s how do I access the Animations array (the array of clips) in a similar manner in a build without reliance on these Editor helper facilities? I suspect there’s no way to do it. But don’t know that for sure.
On the code… I disagree that my code was claustrophobic or otherwise confining. And, for me, it’s got a lot of visual cues that help me see what is what, and find what I’m looking for, fast.
But I still want steak, almost everyday. And pork. And especially free range chickens.
The point is to gather all the data you need outside of runtime and have it ready to use in build, so that you don’t need to use it in runtime.
Your Start callback was just caching the data needed, so instead we’re caching it through the editor. Same result, different means.
It’s pretty common practice to use Editor tools to pre-ready data that would either be costly to do at run time, or - as you’re experiencing - unavailable at run time.