How to add TActorIterator to a TArray? Cast always gives error

I want to add all DoorKey actors that have the tag ConeKEY to an array, in order to be able to get the number of keys using the Num() function. However, i can’t seem to be able to add the items to the array.

The code in ACpp_DoorKey.h:

UPROPERTY()
	TArray<ACpp_DoorKey*> DoorKeys;

And the code in ACpp_DoorKey.cpp:

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

	if (GetWorld())
	{
		for (TActorIterator<ACpp_DoorKey> Itr(GetWorld()); Itr; ++Itr)
		{
			if (Itr->ActorHasTag("ConeKey"))
			{
				UE_LOG(LogTemp, Warning, TEXT("Name: %s"), *Itr->GetName())
				ACpp_DoorKey* DoorKey = Cast<ACpp_DoorKey*>(Itr);
				DoorKeys.Add(DoorKey);
			}
		}
	}

In the attached image you can see the error.

Any help would be appreciated. Thank you.

I think you forgot to attach the image so I’m not totally sure this is correct, but I’d say your problem was on this line:

ACpp_DoorKey* DoorKey = Cast<ACpp_DoorKey*>(Itr);

You don’t need this and I suspect it’s your cast that’s failing. Instead you can just dereference:

ACpp_DoorKey* DoorKey = *Itr;

Omg, it worked! That solved it.
Yes, I forgot to attach the image but I edited the post and added it again. Thank you very much for your help. I will mark the answer as correct and upvote it. Thanks again.