# Test function not working

**URL:** <https://forums.unrealengine.com/t/test-function-not-working/275310>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310 "2014-03-11T02:11:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/1 "2014-03-11T02:11:00Z")

</div>

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;

}

```

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/2 "2014-03-11T02:11:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/3 "2014-03-11T02:11:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/4 "2014-03-11T02:11:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/5 "2014-03-11T02:11:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/6 "2014-03-11T02:11:02Z")

</div>

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"));
	}
		

}

```

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/7 "2014-03-11T02:11:03Z")

</div>

Please help

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/8 "2014-03-11T02:11:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/9 "2014-03-11T02:11:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/10 "2014-03-11T02:11:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/11 "2014-03-11T02:11:04Z")

</div>

How do i set that breakpoint though?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/12 "2014-03-11T02:11:05Z")

</div>

Hi Eshwar,

Does this help? [Debugging - Visual Studio 2015 | Microsoft Learn](http://msdn.microsoft.com/en-us/library/vstudio/sc65sadd.aspx)

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/13 "2014-03-11T02:11:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/14 "2014-03-11T02:11:06Z")

</div>

Any idea on fcolor and how it should work

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/15 "2014-03-11T02:11:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/16 "2014-03-11T02:11:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/17 "2014-03-11T02:11:07Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/18 "2014-03-11T02:11:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/19 "2014-03-11T02:11:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:11am UTC](https://forums.unrealengine.com/t/test-function-not-working/275310/20 "2014-03-11T02:11:09Z")

</div>

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

[Next page](https://forums.unrealengine.com/t/test-function-not-working/275310.md?page=2)
