SetActiveRecursively Affecting Animations

Hi All,

I’m currently attempting to call my split animations using script, however I’ve noticed that “SetActiveRecursively” is triggering and looping the idle (animation state).

My code is below:

	void Update () {
	
	
			
	if (isDead == false ){
					gameObject.SetActiveRecursively(true);


	} 
	
	if (isDead == true){
		
		gameObject.SetActiveRecursively(false);
			moveSpeed = 0;
			moveSpeed = 0;
		gameObject.active = true;
	


	}

The isDead code is used to turn off an enemy when it is killed and then turn it back on when it is respawned. Annoyingly this is locking in the animation to idle and loop, preventing me from using the attack, or death animations on my model.

I have tested that the animation code works by placing it in the function start - If I did this with the “isDead == true” section removed, it worked! If I kept it in it didn’t work.

Any ideas?

Please check settings on Animation component. Most likely you have “Play Automatically” enabled which triggers default animation (set as Clip on Animation component). Disable “Play Automatically”.