Why is this C++ Linetrace Function not showing the Debug LineTrace?

I am trying to call this function created in C++ to Blueprints the BTTask. This function is basically a linetrace that I am firing everytime the AI Spots the player. I don’t know why this function does not show the debug line trace. The line trace fires I just don’t know why the debug line trace does not show up in the viewport. I don’t know if I am creating the linetrace incorrectly for this type of usage any advice would be awesome!! The linetrace never comes in contact with the player.

The Header

UFUNCTION(BlueprintCallable)
		void ShootPlayer(AActor* Actor);

The CPP (Here I am calling a linetrace. For the AI to shoot.)

void ACriminalJill::ShootPlayer(AActor* Actor)
{
	UE_LOG(LogTemp, Warning, TEXT("AIFIRED!!!"));
      //I have a gun in the character's arms. 
	const FVector EnemyPistolStartTrace = EnemyWeaponBaseMesh->GetSocketLocation(FName("EnemyGlockSocket"));
	FCollisionResponseParams ResponseParams;
	FCollisionQueryParams EnemyPistolQueryParams = FCollisionQueryParams(SCENE_QUERY_STAT(WeaponTrace), false, this);
	FActorSpawnParameters SpawnParams;
	SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	PistolQueryParams.AddIgnoredComponent(EnemyWeaponBaseMesh);
	TArray<FHitResult> PlayerHit;
	FRotator CurrentRotation = EnemyWeaponBaseMesh->GetSocketRotation(FName("EnemyGlockSocket"));
    //Here I am getting the player's location which is the actorlocation.
	const FVector EnemyPistolEndTrace = Actor->GetActorLocation();
	UE_LOG(LogTemp, Warning, TEXT("AIFIRED!!!"));
	DrawDebugLine(GetWorld(), EnemyPistolStartTrace, EnemyPistolEndTrace, FColor(255, 0, 0), false, -1, 0, 12.333);
	if (GetWorld()->LineTraceMultiByChannel(Hit1, EnemyPistolStartTrace, EnemyPistolEndTrace, ECollisionChannel::ECC_Visibility, EnemyPistolQueryParams, ResponseParams))
	{
		DrawDebugLine(GetWorld(), EnemyPistolStartTrace, EnemyPistolEndTrace, FColor(255, 0, 0), false, -1, 0, 12.333);
		if (Hit1.Num() > 0)
		{
			for (FHitResult& Results : PlayerHit)
			{
                           UE_LOG(LogTemp, Warning, TEXT("HitSomething"));
				if (ACharacter* Player = Cast<ACharacter>(Results.GetActor()))
				{
                                   UE_LOG(LogTemp, Warning, TEXT("PlayerHealthDecreased!!!"));
                                  //This never gets fired off.
					Player->Health -= Player->HealthDecrease;
				}
				else
				{
                                      UE_LOG(LogTemp, Warning, TEXT("Cast Unsuccesful!!!"));
				}
			}
		}
	}

}

The Task

I created a gun class and I am trying to fire the linetrace from the muzzle and it crashes.

I am calling a function that is within the gun class. I might be casting incorrectly, but at the same time the enemy fires then crashes. So the cast might be correct, but something happens that causes it to crash.

Hi!
I’ve only used Linetracing from BPs, but this here is my first suspect: “The linetrace never comes in contact with the player.” It wont draw the line if it does not hit anything.
The second thing I would do is double check the function parameters. I do not know the order, but might be you are using 0 as time to draw it or maybe it’s just too short of a distance to hit something.
Anyhow here’s also a related chain of posts: https://answers.unrealengine.com/questions/1849/view.html

I am using draw debug helpers. It won’t compile unless I have it and also the the length of the line trace is set to the actor location so the line trace will have the same distance

I did as you said and it worked.

The other problem is that the line trace is spawning in the wrong location…

It supposed to spawn in the muzzle now it is spawning within the floor.

Is it possible that the you are using the starting point from screen space? Like your muzzle exists only in screen space, not world space. Try something like the gun object itself.

Thank you very much you solved my original problem you were right!