I’m making my first videogame. I’m creating my CustomButton class derived from UI.Button. It works entirely on an animator I created, which looks like this at the moment:
I’m trying to make an animator that I can reuse with every button in the game, and for different styles of buttons I just make an animator override controller and change the animations themselves, but the logic behind the transitions and everything needs to always stay the same.
Now, it works wonders. There’s just a couple problems:
- The transition from Normal to Highlighted needs to adapt to the length of the Highlight animation. For example, I’m making a button that takes 5 frames to fade from black to wide background. So, the transition, in order to not look weird, must last exactly the duration of the Highlight clip, like here:

This is of course not just the case from the Normal → Highlighted transitions, in fact, most have this problem.
I tried with toggling off Fixed Duration, but apparently it just means that instead of lasting a fixed amount in seconds, it last a certain percentage of the first animation (as far as I understand, this part of the animation side of Unity I don’t really understand much), which is not what I’m looking for.
Having to change this by hand for every button style and having multiple controller types is absolutely unacceptable and I must find a better soluton.
- The Normal animation is just a single-keyframe looped clip, while the others aren’t looped and have multiple keyframes so that I can control how long the fade lasts.
But what if I wanted to make an idle animation for when the button is highlighted? Can I create a single clip that has some custom loop points, so that I don’t have to do two different states, and so multiple Animator Controller’s?
- Is even using a custom animator for buttons optimal? On a performance level, and design as well? The alternative is using scripts (which works fine, I already did it before, but I have to make a script for every single kind of animation, like fade or scale over time, which is lots of work and repetition), or the default Unity Button (which doesn’t let me animate text and other stuff).
Is the approach I’m using good?
