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 (Interact) 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.
In the character class i got a refrence to the door class, now in the door class i need to get a refrence to the Scene Component so i will be able to call the OnInteract function. here is my code (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"));
if(Door1Cast->test)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("got access to 'test'"));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("didnt get access to 'test'"));
}
}
}
}
any idea on how to a get a refrence to the scene component in the door class?
im new to Unreal Engine 5 so please dont kill me