How to create a "Looping" Cast. C++

Ok I got something that works like that, but I can’t really make a “library” that can be called by any class. Anyway, I’ll leave it here for anyone that wants it.

|YourController.h|

// HANDLE CASTS //
const int16 CastTo_MaxAttempts = 50;
const float CastTo_DelayBetweenAttempts = 0.2f;

UPROPERTY()
AYourCharacter* YourCharacter;
int16 CastTo_YourCharacter_NumAttempts = 0;
void CastTo_YourCharacter();

|YourController.cpp|

void AYourController::BeginPlay()
{
	Super::BeginPlay();

	// HANDLE CASTS //
	CastTo_YourCharacter();
}
// HANDLE CASTS //
void AYourController::CastTo_YourCharacter()
{
	// TRY TO CAST //
	YourCharacter = Cast<AYourCharacter>(GetCharacter());

	// IF SUCCESS //
    if (YourCharacter)
    {
		/*
		* YOUR CODE GOES HERE
		*/
    	return;
    }

	// IF FAIL //
    CastTo_YourCharacter_NumAttempts++;
    if (CastTo_YourCharacter_NumAttempts >= CastTo_MaxAttempts)
    {
        if (GEngine) GEngine->AddOnScreenDebugMessage
			(1, 20.f, FColor::Red, FString::Printf(TEXT
			("%s | /*Cast Failed*/ YourCharacter"), *this->GetName()));
        return;
    }
	// USE TIMER TO RECURSIVELY CALL THE CAST AGAIN //
	FTimerHandle CastTo_YourCharacter_TimerHandle;
    GetWorld()->GetTimerManager().SetTimer(CastTo_YourCharacter_TimerHandle, this, &AYourController::CastTo_YourCharacter, CastTo_DelayBetweenAttempts, false);
}