Test function not working

I have this function which is executed when u fire(left click) and then it performs a trace. If it is not hit it fires. Im using shootergame sample. I did this just to see how the trace works. Please help and tell me whats wrong. also how do i get what the hit location was like in the previous trace. Can anyone please give a good explanation of how the trace works here?
Thanks

void AShooterCharacter::DetectLedge()
{
	FVector Location = GetActorLocation();
	FVector TestLocation = Location + FVector(200,0,0);
	FCollisionQueryParams TraceParams(TEXT("DeathCamera"));
	const bool bBlocked = GetWorld()->LineTraceTest(Location, TestLocation, ECC_Default, TraceParams);

	if(!bBlocked)
		OnStartFire;


}

The code appears to be correct, what problem are you seeing? Note that this trace always tests along world X, did you want forwards (local +X) or down (-Z) instead?

LineTraceTest is a quick yes/no test, it does not give a hit location. If you want that, use LineTraceSingle.

Well i was trying to just meddle around with trace but i think i know what my error is. OnStartFire cant be executed this way i think. But for LineTraceSingle, i want to know if there was a hit and if yes it performs another trace using the HitLocation of the previous +15 in the Z value and 5 in the X value. How would you write that? I couldnt find HitLocation i only found HitResult. Perhaps HitResult.Location?

I tried with the code above only with onstartjump, forcing the player to jump when it doesnt hit anything. But still it is not working and i tried with putting the X vector to 2
Is it because of traceparams
Also i think you are right i want local location so the trace goes in front of my pawn.

Did you try adding a breakpoint or some logging to check whether the problem is the trace or the function you are calling?

Ya i tried a log here is the code. I think it was because i didnt use local X vector.
void AShooterCharacter::DetectLedge() const
{
FVector Location = GetActorLocation();
FVector TestLocation = Location + FVector(2,0,0);
FCollisionQueryParams TraceParams(TEXT(“DeathCamera”));
const bool bBlocked = GetWorld()->LineTraceTest(Location, TestLocation, ECC_Default, TraceParams);

	if (!bBlocked)
	{
		UE_LOG(LogShooter, Log, TEXT("bBlocked"));
	}
		


}

Please help

I’m sorry, I’m not sure I understand your current problem. Is the log not printing? Did you try using local X (forwards)? Did you try making the trace longer than 2 units? Are you drawing the trace to make it clear when it should be hitting something?

My log is not printing. in fact i dont see a line in the game is that supposed to happen? Is there a way where i can see all he traces?

Hi Eshwar,

If you set a breakpoint in the code, can you confirm that the code is executing?

It would be good to establish if we have a logic error in the code, or if the code is not hit.

How do i set that breakpoint though?

Hi Eshwar,

Does this help? Debugging - Visual Studio 2015 | Microsoft Learn

I did DrawDebugLine but its doest show up. Im pretty sure it is because my FColor is wrong. I put
const FColor White

but i dont know how FColor works. Help please?

Any idea on fcolor and how it should work

Hi Eshwar,

Let’s keep with your previous issue and try and work you through that first.

Was your break-point successfully hit? How go your adventures in debugging via visual studio?

I tried DrawDebugLine to see if the function even performs, but i need to know jow fcolor works because i need to see it in the game. also i want to know if it goes in the players local x axis or the world x axis for t he trace location.

void AShooterCharacter::DetectLedge() const
{
FVector StartTrace = GetActorLocation();
FRotator Dir = GetActorRotation();
FVector EndTrace = StartTrace + FVector(20,0,0);
const FColor White;
FCollisionQueryParams TraceParams(TEXT(“WeaponTrace”), Instigator);
TraceParams.bTraceComplex = true;
TCHAR* pMessage = T(“World”);
bool bBlocked = GetWorld()->LineTraceTest(StartTrace, EndTrace, ECC_WorldTrace, TraceParams);
DrawDebugLine(StartTrace, EndTrace, White);
if (!bBlocked)
UE_LOG(LogShooter, Log, TEXT("
%s_"), *pMessage);
}

this is my code now and it crashes when i executed so i know its executing but not properly

Hello Eshwar,

The crash seems quite obvious; I did mention on one of your question that UE_LOG’s format is similar than printf hence %s expects a null-terminated string and not a character, pMessage in this case is a pointer to a TCHAR but * pMessage i.e. pMessage being dereferenced is the first character within that string, considering that W (ASCII) is equivalent to 87 in decimal and 0x57 in hex, you’re actually passing a pointer to memory address 0x57 assuming it’s non-readable/writable which seems like it isn’t in this case will cause a seg-fault. Remember that TCHAR* pMessage = _T( “World” ) declares a pointer to a TCHAR called pMessage and assigns it “World”, * pMessage however is not equivalent to pMessage, it’s equivalent to dereferencing pMessage and accessing the value in the base address of pMessage which in this case is W, likewise *( pMessage + 1 ) would be ‘o’ and would be accessing pMessage at it’s base address with a one byte offset due to the data-type. If however you wanted to print out the first letter of pMessage then you’d change the format to %c which would print the character.

As for FColor, you seem to be rather confused at that; FColor is simply a class just like FVector and declaring it assigns it’s members to a known value (assuming default assignment occurs). FColor has a few constructors and you can create a color by simply calling one of its constructor and passing it as argument to a function that expects an FColor.

Ah thanks it is working now i know it executes. I saw the debug line and now i just need to fix the specifications

So i just realized debugline works but the linetrace doesnt. Here is my code and it performs every tick when the character is jumping state

void AShooterCharacter::DetectLedge() 
{
	const FVector Start = GetActorLocation();
	FRotator Dir = GetActorRotation();
	const FVector End = Start + Dir.Vector() * 2;
	FHitResult OutHit,Hit;
	const FColor White;
	FCollisionQueryParams TraceParams(TEXT("WeaponTrace"), Instigator);
	TraceParams.bTraceComplex = true;
	TCHAR* pMessage = _T("World");
	const bool bBlocked = GetWorld()->LineTraceSingle(OutHit, Start, End, ECC_PawnMovement, TraceParams);
	if (bBlocked)
		DrawDebugLine(Start, End, White);
}

So when it is supposed to have hit something it doesnt draw a debug line? help