Hey, guys!
I’m so frustrated, because I’ve been sitting for hours on google, trying to figure this out.
I have this BlueprintNativeEvent in C++, and I can access it in my Blueprint, but it never gets called. See code below for details about my setup for this.
I have no issue accessing the variables or anything else than get this event fired.
The only thing I want now is to see “FINALLY!!!” pop up on my screen.
Other solutions I’ve tried
Changing it to BlueprintImplementable and made the modification in my code for it to work, but still nothing.
Removing the parent node for the event.
With and without “BlueprintCallable”
How it looks in my blueprint. This is the event graph in the child Blueprint:
.h file:
//For updating HUD
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "HUDEvent")
void UpdateCurrentAmmoHud();
void UpdateCurrentAmmoHud_Implementation();
.cpp file:
void UTP_WeaponComponent::Fire()
{
if (Character == nullptr || Character->GetController() == nullptr)
{
return;
}
// Try and fire a projectile
if (ProjectileClass != nullptr)
{
UWorld* const World = GetWorld();
if (World != nullptr)
{
APlayerController* PlayerController = Cast<APlayerController>(Character->GetController());
if (PlayerController != nullptr)
{
//Decrements amount of bullets in clip
CurrentAmmoInClip--;
//Updates the hud through BP implementation
UpdateCurrentAmmoHud_Implementation();
const FVector StartLoc = PlayerController->PlayerCameraManager->GetCameraLocation();;
const FVector ShootDirection = PlayerController->PlayerCameraManager->GetCameraRotation().Vector();
FVector EndLoc = StartLoc + ShootDirection * ShootingDistance;
FHitResult HitResult;
FCollisionQueryParams CollisionParams;
CollisionParams.AddIgnoredActor(Character); //Excludes weapon owner from the line trace. You can't shoot yourself :D
//Determines if it is a hit or not
bool ShotHit = World->LineTraceSingleByChannel(HitResult, StartLoc, EndLoc, ECC_Visibility, CollisionParams);
DrawDebugLine(GetWorld(), StartLoc, EndLoc, FColor::Orange, false, 2.0f);
if (ShotHit)
{
//Draws a small red box at the hit location
DrawDebugBox(GetWorld(), HitResult.ImpactPoint, FVector(5, 5, 5), FColor::Red, false, 2.0f);
}
IsReloadable = true;
if (CurrentAmmoInClip != MaxClipCapacity || CurrentReserveAmmo != 0)
{
ReloadWeapon();
}
else { return; }
}
}
}
void UTP_WeaponComponent::UpdateCurrentAmmoHud_Implementation()
{
//GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Weapon fired"));
}
I’ve also tried changing:
UpdateCurrentAmmoHud_Implementation();
to