Animator - How to make animations NOT play on Awake

Basically, I created an animation for walls to fall upon a trigger to cage the player in with the boss. The player touches the cube I set as the trigger and BAM!!! He’s trapped! Time to fight or die!

Anyway, the animation plays on Awake. Which obviously I don’t need that. I’ve clicked on the object I have the amimation connected to but there’s no “Play on awake” check box. I clicked on the animation itself, turned the “Loop Time” off so that it stops at the end of animation; however, there still isn’t a checkbox to turn off the Play on Awake.

Any advice on where to look or how to fix this issue?

Open the animator, click the Transition line from Entry to the node that has the animation. Set it to only transition when the appropriate trigger has been called.

Ideally you’d just leave the animator component disabled though instead of having potentially dozens or hundreds of animators running in the scene. And just have a script on the object which enabled the animator when the collision happens and sets the trigger on the animation to begin it.

2 Likes

Thank you for the response!
I’m not very familiar with the animator yet. Do I need to click on the object that I have the animation set to first? Then open the animator?

Basically, I created two walls from cubes and I textured them. Then I added both the walls inside or an empty object. I added the animation to the empty object. So as of now, the current “Player Controller” is set to the name of my empty object ( BossCage ). Which the animation works great.

There’s an empty slot for “Avatar” so I’m wondering if I can add my Player to the avatar and set the culling mode to Cull Completely from “Always animate”? Would that work?

I did find a solution to my problem. (It required a LOT of tinkering with the state machine because I never used it before)

Opened up the Animator, right-clicked, created new state, right clicked ON THE NEW STATE and made it default state.
Then created a new c# script, created an Animation variable “ani” and (NOTE - I attached the script to my event trigger)
inside my OnTriggerEnter function, I then wrote a piece of code that grabs an animation by its name.

However, there must be a way to grab the animation component without hard coding its name. what if I want to use this same script every level? I’d need to attach the script and put the new name in everytime. I want it to grab the component as the player approaches. Any ideas?

I’d recommend going through a youtube tutorial or the ones on the tutorial section of the Unity website that go over the features of the animator.

But to answer that question, generally you’d use a common state name across different animation controllers so you can identify state by name in a generic way.
But for something as simple as this, you shouldn’t need to grab the state name. Click the “Parameters” tab above the layers in the Animator. You can add different parameters to allow a state to transition. Create a “trigger” parameter, perhaps called “CollisionAction”. Then, have a transition between an empty state and the state that has your animation clip, and that transition has a “Condition” set on it to only transition when “CollisionAction” has been set.

Also, if you’re working with prefabs, then you could simply have the correct state name to look for as a saved field on your script on that prefab which the script will read from.

1 Like

My thought process is having a different Boss Cage for each level, but be able to re-use the same animation for each level. This seems a bit hairy because the location of each object would be on different scenes, and different coordinates. I have a LOT to learn about animations designed within Unity as well as the state machines. I’ll take your advice and start researching everything I can find because I’m total N00b status here lol
Thanks for your time, friend! Stay blessed!

Ahh, well the issue with different coordinates is solved using the “Root Motion” option on the animator.

https://www.youtube.com/watch?v=Kn6jxLWA31M

1 Like

That was pretty dope! Preciate that! I have several enemy types that hop around, so I’m sure I’ll be using this when I revamp my levels before Beta :slight_smile:

What I’m trying to figure out now is why sometimes my animations cause my player to e able to walk right through them. It’s as though their colliders no longer exist. For example, my Boss Cage drops, but the player can walk straight through the walls. I’ve checked my 2D terrain and the walls AND colliders are lined up on the ground. No IsTrigger clicked and the box colliders are there. I noticed this happened with some enemies too.

Any idea what causes this and how to fix it?

If you’re moving them using animation alone, then that can be an issue, since animation is just going to set absolute position values, it’s not going to trigger a collision check. You’ll need to make sure the animate objects have kinematic rigidbodies and the animator is set to Animate Physics mode. But that’s usually not ideal either.

For a 2D game, usually you’d just have scripted movements, and animations would play based on those movements, the environment around them and actions taken towards them. One option is using a Navmesh or pathfinding solution for the units to run on to automatically avoid obstacles. Or code your own simple checks using using raycasts to see what colliders are around the character/enemy and have it prevent them going in that direction, turn around, allow climbing, etc… depending on what the rays hit.

1 Like

Admittedly, I avoided scripting the animation sequence manually, but opted to create an animation for what I wanted the walls to do. I thought it would be a quick way to do what I wanted it to do because I scripted ONE moving floor tile and it was a good amount of code and was rough getting the coordinates precise. So I switched to using the built in animations. works for the most part, however, it has a few bugs.

Hmmm… I would think the cubes have built in rigidbodies, so is what you’re saying is I need them to be IsKimatic plus set my animator(on these specific objects) to Animate Physics mode?

Yes, that way it should allow the animations to properly interact with other physics objects in the scene.

1 Like

It’s maybe a bit late, but my solution is you stop your animator when awake
Ex:
private void Awake()
{
AniObj_ = GetComponent();
Par_WaterSource.Stop();
}