# Random montage animations on Tick on an AI character

**URL:** <https://forums.unrealengine.com/t/random-montage-animations-on-tick-on-an-ai-character/569143>\
**Category:** AI\
**Tags:** unreal-engine, UE4-27, question\
**Created:** [May 29, 2022, 10:58am UTC](https://forums.unrealengine.com/t/random-montage-animations-on-tick-on-an-ai-character/569143 "2022-05-29T10:58:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brok4d](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/brok4d/32/490601_2.png) [@brok4d](https://forums.unrealengine.com/u/brok4d)\
**Post date:** [May 29, 2022, 10:58am UTC](https://forums.unrealengine.com/t/random-montage-animations-on-tick-on-an-ai-character/569143/1 "2022-05-29T10:58:47Z")

</div>

Hello everyone, I need the assembly animations to be random when it finds the character and this is the way that has occurred to me, but it does not work well sometimes, the animations are mixed sometimes, how could I do it I have been trying for days and almost I am, thank you.

Controller AI

```auto
void ADarkShullAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	ADarkShullCharacterAI* CharacterAI = Cast<ADarkShullCharacterAI>(GetPawn());

	if (DistanceToPlayer > AISinghtRadius) {
		
		bIsPlayerDeteted = false;
	}
	if (CharacterAI->NextWaypoints != nullptr && bIsPlayerDeteted == false)
	{
		MoveToActor(CharacterAI->NextWaypoints, 5.f);
	}
	else if (bIsPlayerDeteted == true)
	{
		ADarkShullCharacter* Player = Cast<ADarkShullCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
		
		MoveToActor(Player, 50.f);
		CharacterAI->MontageIndex = (1 * 400 ) + (FMath::Rand() % ((8 * 400) - (1 * 400) + (1 * 400)));
		//UE_LOG(LogTemp, Warning, TEXT(" %d"), CharacterAI->MontageIndex);
		CharacterAI->AttackCharacterAI(DeltaTime);
	}
	
	
}

```

Character AI

```auto

void ADarkShullCharacterAI::AttackCharacterAI(float DeltaTime)
{
	GetWorld()->GetTimerManager().SetTimerForNextTick(this, &ADarkShullCharacterAI::AttackAI);
}

void ADarkShullCharacterAI::AttackAI()
{
	
	
	switch (MontageIndex)
	{
		case (1 * 400):
			AttackAISlice1();
		break;
		case (2 * 400):
			AttackAISlice2();
			break;
		case (3 * 400):
			AttackAISlice3();
			break;
		case (4 * 400):
			AttackAISlice4();
			break;
		case (5 * 400):
			AttackAICombo1();
			break;
		case (6 * 400):
			AttackAICombo2();
			break;
		case (7 * 400):
			AttackAICombo3();
			break;
		case (8 * 400):
			PlayAnimMontage(BallMagicAnim, 1.0f, FName("Start_1"));
			BallMagicAudioComponent->SetPitchMultiplier(0.5f);
			BallMagicAudioComponent->Play(0.f);
		default:
			break;
	}
	
}

```
