Getting reference of custom actor class

I have a class called AMyDoor(derived from AActor) parent of a door blueprint and I want to get an object of AMyDoor whenever the PlayerController hit it with raycast.I can get the AActorcomponent of the Door object using the HitResult.GetComponent() and HitResult.GetActor() but not the AMyDoor component. I cannot use FindComponentByClass, how do I get the refernce of my custom class instead of its parent class?

Thanks

You must cast it to the derived class, something like

[...]Cast<AMyDoor>(HitResult.GetActor())[...]

this will return the reference to the AMyDoor instance or null if it fails, so check the result validity before using it for anything

with this reference you will have access to the methods and members from AMyDoor

AMyDoor is a actor, not component. To get you AMyDoor from HirResult try this:

AMyDoor* Door = Cast<AMyDoor>(HitResult.GetActor());

If hit did not happens with AMyDoor and cast fail will be null;

Ah thanks! it worked.

I was doing HitComponent->GetComponent()->GetOwner() and casting like you mentioned…but the Owner was null, so whats exactly is difference between between GetActor() and GetOwner()?

If im not mistaken GetOwner() in scene component will return other component that this component is attached to only root component will return AMyDoor here, GetActor() will always return a actor that was hit so use that

Make sense, GetOwner() was always returning null.