How to Execute a function from the players line trace

i have a line trace set up in my Player.CPP

// Get player view point
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);

// Log out to test
//UE_LOG(LogTemp, Warning, TEXT("Location: %s, Position: %s"), *PlayerViewPointLocation.ToString(), *PlayerViewPointRotation.ToString());

FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;

// Draw a red trace in the world to visualise
//DrawDebugLine(GetWorld(), PlayerViewPointLocation, LineTraceEnd, FColor(255, 0, 0), false, 0.f, 0.f, 20.f);

// set up query parameters
FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetWorld()->GetFirstPlayerController()->GetPawn());

// Line trace
FHitResult Hit;
GetWorld()->LineTraceSingleByObjectType(OUT Hit, PlayerViewPointLocation, LineTraceEnd, FCollisionObjectQueryParams(ECollisionChannel::ECC_GameTraceChannel1), TraceParameters);

And i have a OpenDoor.CPP which i have simple code to open a door

InputComponent = GetWorld()->GetFirstPlayerController()->GetPawn()->FindComponentByClass();

if (InputComponent)
{
	InputComponent->BindAction("Interact", IE_Pressed, this, &UDoor::OpenDoor);
}

void UDoor::OpenDoor()
{
JustInteractedWithDoor = false;

if (DoorHit && !DoorIsOpen && !JustInteractedWithDoor)
{
	OpenDoorBP.Broadcast();

	DoorIsOpen = true;
	JustInteractedWithDoor = true;
}
if (DoorHit && DoorIsOpen && !JustInteractedWithDoor)
{
	CloseDoorBP.Broadcast();

	DoorIsOpen = false;
	JustInteractedWithDoor = true;
}

}

I want the code in the Door.CPP to Run when the Line trace from Player.CPP hits the object that it is looking for, how would i do that?

First you’ll need to use the hitinformation to determine what object you’ve hit.
FHitResult Hit contains the hitinformation after you do the LineTraceSingleByObjectType(). So with hit you can set up a condition soemthing like:

if (hit /*check if hit is valid*/ )
{
    Door door = cast<Door>(hit.actor); // check if the actor we hit is a door actor
   if (door /*check if door is valid*/ )
{
 door->opendoor();
}
}

and that should take care of it. (just using pseudocode, you’ll have to adjust some things)

And that is done within the Door.CPP?