Controling simple animations

I’m trying to add animations to an fx controller script, and unfortunately I’m having trouble working around (or with) the animation controller.

I’ve already got a controller that controls various fx (such as audio, particles, lens flares, trails, visibility) based on various states of an object, like health, throttle, alive, dying, and a host of other parameters.
It’s pretty straight forward. You drag and drop the effect, and then you can assign a condition when the effect is to be active.

I’d like to add some simple animations to the mix as well. (like parts opening and closing)
At it’s most basic, it would look like this:
Drag and drop the animation into the controller, and when the monitored value is true, play the animation. When it’s false, play the animation in reverse.

But I’m fighting with the animation controller. There doesn’t seem to be any way for my script to know what variables an arbitrary animator controller is using without a lot of hard coding, so there’s no good way to link control.
And the thing is, I don’t really need a state machine; I’ve already got one. And having two of them to monitor the same thing seems like a waste.

Is there not a simple way to just play an animation clip on a specific object? Without having to create a whole state machine every time?
Alternately, however, I can see the use for some of the more complex states, and transitions. So, ideally, I’d like to be able to integrate with an animation controller in a generalized way. That is, without having to hard code each one.

I’m new to Unity’s animator, but all the tutorials I’ve seen haven’t been relevant to what I’m doing.

I don’t really understand this “link control”. Won’t a trigger condition work for simple open/close animation?

Are you looking for animation instead of animator?
This might help -

Animation is a legacy feature and Unity recommends not using it. Are you saying to ignore that recommendation?
But it looks like the animator is using animations, so that seems a little contradictory.

At any rate, I want to play a specific animation from script. Using the animation controller, it seems I have to set a bool or a trigger to cause a state change to activate a particular animation, and I don’t see a direct way to just get and play an attached animation in a generalized fashion.

The problem is, how is the script supposed to know what the bool, trigger, or animation names are?

For example, if I want to play a ParticleSystem, I can just GetComponent() the particle system and then ParticleSystem.Play()
But for animation, I can only attach and GetComponent() on the Animator, and that doesn’t seem to have information on how to access the animations within.
I suppose I could just ‘make a rule’ the the fx controller always plays the animation at index 0 (or something) but this doesn’t seem terribly ideal.

https://forum.unity3d.com/threads/whats-the-difference-between-animation-and-animator.288962/
I’m saying use whatever method you need to get the job done, but how you worded the original post sounded like animation instead of animator. :wink:

https://docs.unity3d.com/Manual/AnimationParameters.html

Consider watching the animation learn content - I believe all the info you are missing is provided in there. Will take you about 30 minutes to get through the relevant videos, and probably only 5 to directly find the specific info you need.

That link doesn’t have a video, but I suspect you mean this. I’m familiar with much of this material.

Maybe I’m not making myself clear.
The script you linked is a perfect example of what I’m talking about. All the parameter names are hard-coded, which is exactly what I’m trying to avoid.

I don’t see a way to change a parameter (or activate a state) without hard-coding the names. Which means every object is going to need a specifically tailored script. This can lead to dozens of different scripts that all do essentially the same thing, and this is unworkable. It sounds like an anti-pattern.

The alternative seems to be to just make sure the animation controllers use specific predefined parameter names, but this isn’t ideal, and seems very easy to break.

1 Like

The Playables API seems like what you’re looking for. It’s still experimental, but it does allow for just playing animations directly on objects.

Unity has promised to not deprecate the Animation component before there’s alternatives that does everything it does. That includes playing a clip without a controller. I believe Playables is what’s going to be the final replacement, but in the meantime, you can just use Animation.

4 Likes