In the Inspector, is it possible to display a dropdown that allows selecting an Animator Parameter?
Let’s say I have a GameObject that has an Animator component and a Script component on it.
In the script, I would like to have a serialized field animatorParameter that refers to one of the parameters of the attached Animator component. At the moment, this simply is a string, so it is subject to typos and having to remember/check what the parameter name was.
I am thinking it would be. a lot nicer to have a dropdown instead that allows selecting from all of the Animator parameters. Is this possible?
You could write a custom editor for it, you can get the parameters from here and then generate a drop down menu from the parameter’s names.
1 Like
Yes, that’s exactly what Ryan Hipple criticized in his ScriptableObject talk from 2017. I agree that a ScriptableObject approach would actually be quite nice here. Unfortunately it is still a string binding. Yes a PropertyDrawer would be possible, though you would need to actually reference the Animator to get the list of potential parameters and that reference would need to be available at the thing the PropertyDrawer edits. You also can’t really keep it in sync. So even when you have a dropdown and you select an option, when you rename a parameter in the Animator, that change would not be reflected in some buried script where you had selected this parameter.
So a PropertyDrawer may be useful, but certainly not as streamlined as one might hope. A true “reference” would be awesome. They could make an “AnimatorParams” scriptable object which could hold several sub scriptalbeobject assets for each parameter. The animator would just use theAnimatorParams object and everything else could reference the specific sub assets. Unfortunately that would be something that Unity has to implement for us.