Hey guys,
I have been sitting on this simple thing all day. I have the following setup.
I have a ATextRender attached to another Actor SM_TableRound
On my PlayerPawn I have code that returns FHitResult of the first PhysicsBody in reach of my pawn. Now the code is quite simple really,
FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());
/// linetrace out
GetWorld()->LineTraceSingleByObjectType(
OUT HitResult,
GetReachLineStart(),
GetReachLineEnd(),
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
TraceParameters
);
/// GetActor of what we "hit"
AActor* ActorHit = HitResult.GetActor();
if (ActorHit)
{
/// here i would like to change the text and rotation of the attached ATextRender actor that we "hit"
}
As per above, the part where I check ActorHit is working fine. I even figured out how to spawn new actors as part of the ActorHit. like so ::
ATextRenderActor* SomeText = GetWorld()->SpawnActor<ATextRenderActor>(
ATextRenderActor::StaticClass(),
FVector(0.f, 100, 170.f),
FRotator(90.f, 180.f, 0.f)
);
SomeText->GetTextRender()->SetText(FString::Printf(TEXT("name = %s"), *ActorHit->GetName()));
SomeText->AttachRootComponentToActor(ActorHit);
SomeText->SetActorScale3D(FVector(2.0f, 2.0f, 2.0f));
But I do NOT know how to access the ATextRender actor that is already attached… The idea is basically I have these ATextRenders attached to my Actors and when the player gets close the text becomes visible and I can change it etc at runtime…
I have tried the following… All no success.
ATextRenderActor* textTest = ActorHit->Children.FindItemByClass<ATextRenderActor>(); /// crashes UE
ATextRenderActor* textRender = ActorHit->FindComponentByClass<ATextRenderActor>(); /// won’t compile
My logic just tells me since I already have the actor we are “hitting” it should be super simple accessing child actors / components ?? Or is it that I have to get the owner again first then the root component then the child etc etc ?? If so could someone point out how?
I would really appreciate your help guys. Help me and I’ll buy you a beer
Cheers