How can I get an ammo counter working?

Ok, so What I want to do is get an ammo counter working for my HUD, but it needs to work from C++ meaning I have code in place that I want to use in blueprints to make the counter.

this is the code block I want to reference for the count, Obviously the Ammo part of this.

{
// DrawDebugPoint(GetWorld(), Hit.Location, 20, FColor::Red, true);
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(),
BulletHit, Hit.Location,
ShotDirection.Rotation());
UGameplayStatics::PlaySoundAtLocation(GetWorld(),
ImpactSound, Hit.Location,
ShotDirection.Rotation());
AActor* HitActor = Hit.GetActor();
if (HitActor != nullptr)
{
FPointDamageEvent DamageEvent(Damage, Hit,
ShotDirection, nullptr);
AController* OwnerController = GetOwnerController();
HitActor->TakeDamage(Damage, DamageEvent, OwnerController, this);
Ammo -= 1;
Ammo = FMath::Clamp(Ammo, 0, 99);
UE_LOG(LogTemp, Warning, TEXT(“Ammo Left %i”), Ammo);
}
}
}

also I have a Blueprint derived from this called BP_ CurrentWeapon

And I want to put this to work into

I think it needs reference to the Gun that the Player Character is holding at the time of instantiation…But I don’t know how to point it to that particular weapon?

Hello! Where are your Player equip logic? In C++ or in BP? The most often solution for such things are events and delegates. At the moment when you Player change weapon he/she raise an event/broadcast delegate with some info - what weapon is equipped now, for example. UI widgets (or even HUD!) subscribe to this event/delegate and just fire some logic on it.

So the player spawns with the rifle in question as the default weapon. And yes this is done in C++ and I have BP class based on said C++ classes. As it stands when I cast to my BP_ MainCharacter There is no “Gun” class to come off of As BP MainCharacter pin This is where I have the issue.

Yes I realize this node doesn’t work as is. and what this node was to be is to Promote it as a usable variable.