How to compare actor hit in raycast to a subclass object?

Hello, I was wondering if someone could help me acquire some knowledge aha… I’m unsure how to compare the value of an actor returned by a raycast to the value of a class that is the subclass of another.

The code provided in the “Code Sample” are the contents of a class named “Pickup”. This class is a subclass of its parent “Interactable”. The value returned in the statement “interactingCharacter->returnRaycastActor()” is unique/different to the value returned if the statement was to be placed within the “Interactable” parent class, however the value returned by the cast “Cast(this)” is equivalent to the value returned in the parent class for both the same cast and for the previously mentioned statement. I’m unsure how to resolve this issue - I’m sure it’s just a component of inheritance that I’m forgetting (Perhaps it’s because I have no explicit constructor for the Pickup class?).

Thanks in advance for any help.

Code Sample:

// Defines the behaviour caused when the player interacts with the prop.
void APickup::interactImplementation()
{
	if (checkingForDirectView)
	{
		ASandboxGameCharacter *interactingCharacter = Cast<ASandboxGameCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));

		if (interactingCharacter->returnRaycastActor() != nullptr)
		{
			GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green, FString::Printf(TEXT("The actor being hit is a: %s"), interactingCharacter->returnRaycastActor()));
			GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green, FString::Printf(TEXT("The actor being hit is meant to be a: %s"), Cast<AActor>(this)));

			if (Cast<AActor>(this) == interactingCharacter->returnRaycastActor())
			{
				Destroy();
			}
		}
	}
}

I know this question is almost 2 years old but it’s the first one that came up in a search when I was trying to find this out for myself.

To do it, you need to call TSubclassOf

In my case it became:

    if (TSubclassOf<AHDEnemyMaster> EnemyHit = TSubclassOf<AHDEnemyMaster>(HitResult.GetActor()->GetClass()))
{
// Your code here
}