Problems with LineTracing and Childblueprints

Hello,
I have got a little problem with Linetracing in C++.
I have got a base C++ Character class which contains variables and functions.
Then I have created a Blueprintclass derived from this class and created a few Childclasses.
The Base class is never used in Game only the childblueprints of it. So my problem now is, when I use the Linetrace function to detect which Actor is hit etc. my output Log shows that the Linetrace has been done twice, because I have got another Child bp placed in the world, which is not possessed.
How can I prevent it from doing LineTracing.
I dont want to deny doing LineTracing for all other characters who are not possessed, because in the future I want to implement an AI Controller.

So the thing I am trying to do is, to only apply LineTracing for the character who is actually shooting, and ignore every other class.

I really hope someone can help me and I am sorry for my limited vocabulary…

AnGaraa

Could you show the codepart that does the linetrace

void ABaseCharacter::RequestFire()
{
ABaseCharacter* PlayerCharacter = Cast(GetWorld()->GetFirstPlayerController());

		FVector CameraLocation;
		FRotator CameraRotation;

		FVector ViewLocation = GetWorld()->GetFirstPlayerController()->GetCharacter()->GetMesh()->GetSocketLocation(TEXT("ViewSocket"));
		GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(CameraLocation, CameraRotation);
		FVector StartTrace = ViewLocation;
		FVector EndTrace = ViewLocation + (CameraRotation.Vector() * 10000.0);
		FHitResult HitResult(ForceInit);
		FCollisionQueryParams TraceParams(FName(TEXT("WeaponTrace")), true, this);
		TraceParams.bTraceAsyncScene = true;
		TraceParams.bReturnPhysicalMaterial = true;


		if (GetWorld()->LineTraceSingleByChannel(HitResult, StartTrace, EndTrace, ECC_Visibility, TraceParams))
		{
			DrawDebugLine(GetWorld(), StartTrace, EndTrace, FColor(255, 0, 0), true);

			if (HitResult.GetActor())
			{
				UE_LOG(LogTemp, Warning, TEXT("Hit Actor: %s"), *HitResult.GetActor()->GetName());

				if (CurrentWeapon)
				{
					UE_LOG(LogTemp, Warning, TEXT("Used Weapon : %s"), *CurrentWeapon->GetName());
					SendDamageRequest(HitResult.GetActor(), CurrentWeapon->GetWeaponDamage());
				}
				else {
					UE_LOG(LogTemp, Warning, TEXT("CurrentWeapon NULL"));
				}
			}
			else {
				UE_LOG(LogTemp, Warning, TEXT("No Actor Found"))
			}
		}
		else {
			UE_LOG(LogTemp, Warning, TEXT("Did not Hit anything!"))
		}
}

This is called when I press the Fire-button.

And this is my Log:

 LogTemp:Warning: Hit Actor: Rabbits_BP_430
    LogTemp:Warning: CurrentWeapon NULL
    LogTemp:Warning: Hit Actor: Rabbits_BP_430
    LogTemp:Warning: CurrentWeapon NULL
    LogTemp:Warning: Hit Actor: Landscape_0
    LogTemp:Warning: CurrentWeapon NULL
//Thats my Character which is possessed
    LogTemp:Warning: Hit Actor: Rabbits_BP_430
    LogTemp:Warning: Used Weapon : AWP_BP_C_0
    LogTemp:Warning: Applied 78.000000 ; Only 102.000000 HP left!

I think your problem lies in the binding to your fire button action event. So when you bind it, you can do this conditionally with something like this in your character code

if (GetController()->IsLocalPlayerController())
{
  // bind RequestFire() here to fire action
}

Hope this helps.

Oh yes thank you that solves my problem. I have got only one log now.
But I don’t know if I could use this also in the AI Controller.
Is IsLocalPlayerController() checking if there is a real person behind the controller? Or did I get it wrong?

Soon I wanna implement an AI Controller and there I also have to make sure, that only one player is shooting, not everyone else. Can you tell me how I can solve that?

The functions IsLocalPlayerController() and IsPlayerController() both check if the controller is a PlayerController (the “Local” variant is used for multiplayer games, don’t know if you need it). So they should return false if the pawn is controlled by an AIController. I hope I’ve got your question right and this helps.

Actually my question was, how I can do it in the AI Controller.
I dont know how to explain it properly in english,. but I need a function something like : IsShootingChildBlueprint()… So that only THIS child shoots and not all the other ones.

Maybe I should wait until I finish the AIController and ask again when I still have problems with it.

So your character class has a function RequestFire, which does the line trace and applies damage to the hit actors. These characters are either controlled by a PlayerController or an AIController.

So the character controlled by a PlayerController will react on input from the player. This is done by the conditional binding from above. So when the player hits the fire button, the binding calls RequestFire. The characters controlled by an AIController won’t react to this input, since we used the function IsLocalPlayerController, which returns false for AIControllers.

So the characters controlled by an AIController will do nothing so far. A typical procedure now would be to create a behaviour tree and a “ShootAt” task. Then you can for example check if your AI character sees an enemy, if it is in range, if it has ammo, etc. and then start the ShootAt task after setting the target in a blackboard connected to the AIController. And this ShootAt task would then call the RequestFire function. And since every AIController runs its own behaviour tree, each AI character shoot independently.

I really hope I got your question right this time :smiley:

Oh yes that was exactly, what I was looking for. I think I have finally got it now :smiley: Much thanks