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