Basically, i want a door to open in unreal engine 5 with c++. I downloaded a door mesh from Sketchfab but the pivot point was at the senter of the mesh, so i created a actor class and attached a Scene component to it and to the scene component i attached a mesh then i kinda moved the mesh so the pivot point of the scene component would be at the buttom left corner of the door mesh. i already setup a function in the character that will be executed when he is looking at the door and press on the e key I also setup a function in the scene component (OnInteract) that should rotate the door 90 degrees. the problem is that i need to call this function from the character class.
here is the code for the OnInteract function in the SceneComponent:
void UDoorSceneComponent::OnInteract()
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("The function is called"));
FRotator NewRotation = GetRelativeRotation();
NewRotation.Yaw -= 90;
SetRelativeRotation(NewRotation);
}
code for the Interact function in the character class:
void APlayerCharacter::Interact()
{
FHitResult HitResult;
//Makes an invisible line between the Start and End point
FVector Start = FollowCamera->GetComponentLocation();
FVector End = Start + FollowCamera->GetForwardVector() * InteractLengh;
// if something is between the line then it stores the information in HitResult
GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECollisionChannel::ECC_Visibility);
// Cast to Door. will return a nullptr if the object between Start and End wasnt the door
ADoor1* DoorCast = Cast<ADoor1>(HitResult.GetActor());
// if Door exists (not a nullptr) run the open door funcion
if(DoorCast)
{
// Got the actor refrence
AActor* Door1Act = UGameplayStatics::GetActorOfClass(GetWorld(), ADoor1::StaticClass());
ADoor1* Door1Cast = Cast<ADoor1>(Door1Act);
if(Door1Cast == nullptr)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("nullptr"));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("not nullptr"));
}
}
}
as you can see, i have tried to get a refrence to the door class but i dont know how can i execute the OnInteract function from here.. I realy tried looking this up on google and didnt really found something. I use manjaro linux as the operating system. Im also new to Unreal Engine so please take it easy :) thanks
edit: I added some debug messages and added a bool named test in the door class (set to true by default) then in the Interact function in the character class i added an if statement if(Door1Cast->test) that if its true ill get a screen debug message and i runed the code and i did get the debug message. I think that if i can get a refrence to the DoorSceneComponent in the Door1 class. Any ideas how?