Hey Community, I just wanted to check with you guys on something that I found a little odd.
I’ve been handling Line Tracing and checking by String Name (If anybody knows a better method, one including pointers then PLEASE post an example. I would be grateful, thank you.) and I discovered something a little odd.
I had created a new Actor Class, placed it in the world and even gave it a name. The same name as the regular cube prop I had placed down. The real catcher however is that both have collisions set to Block All, this particular Actor does not want to invoke the correct debug message and i’m wondering why.
I had also created a test to determine if the line was hitting non-actors as well and it seems to identify as an actor but clearly the name of the actor isn’t working.
// ProjectX2Character.cpp
void AProjectX2Character::RayTracing()
{
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, FString::FString("Func Ray Tracing"))
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Red, FString::FString(*GetName()));
if (*GetName() == "TestingName")
{
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Cyan, FString::FString("You got it!"));
}
}
FString * AProjectX2Character::GetName()
{
FVector CameraLoc;
FRotator CameraRot;
GetActorEyesViewPoint(CameraLoc, CameraRot);
FVector StartTrace = CameraLoc;
FVector EndTrace = CameraLoc + (CameraRot.Vector() * 5000);
static FString testString;
FCollisionQueryParams TraceParams
(
FName(TEXT("GetName")),
false,
this
);
FHitResult HitResult;
if (GetWorld()->LineTraceSingle(HitResult, StartTrace, EndTrace, ECC_Visibility, TraceParams))
{
if (HitResult.GetActor())
{
if (HitResult.GetActor()->GetName() == "TestingName")
{
testString = HitResult.GetActor()->GetName();
}
else
{
testString = FString("Nothing");
}
}
else
{
testString = FString("Not an Actor");
}
DrawDebugLine
(
GetWorld(),
StartTrace, // Start Trace
HitResult.Location, // Hit Result Location
FColor(255, 0, 0), // Red
false, // Persistent Lines
5.0, // Time
0, // Depth Priority
5.0 // Thickness
);
}
return & testString;
}
////////////////////////
LightSwitchCodeOnly.cpp
ALightSwitchCodeOnly::ALightSwitchCodeOnly(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
Box1 = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("TestingName"));
Box1->SetRelativeScale3D(FVector(5, 5, 5));
RootComponent = Box1;
Box1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlap); // set up a notification for when this component overlaps something
Box1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchCodeOnly::ExitOverLap); // set up a notification for when this component overlaps something
}