diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 7931ae17..41aa0ea4 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -534,12 +534,15 @@ void AEndlessVendettaCharacter::EquipPrimary() //For when you already have all your weapons and ur switching with 1 and 2 or when your picking up a weapon with a weapon in hand if (PrimaryWeaponClass != nullptr) { - GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("non ifstatement code running")); - //PrimaryWeaponActor->AttachToComponent(FirstPersonArms, AttachmentRules, FName("GripPoint")); - HeldWeapon->SetChildActorClass(PrimaryWeaponClass); + int PreviousAmmoCount = -1; if (PrimaryWeaponClass == PrimaryWeaponActor->GetClass()) { - Cast(HeldWeapon->GetChildActor())->currentAmmoCount = Cast(PrimaryWeaponActor)->currentAmmoCount; + PreviousAmmoCount = Cast(PrimaryWeaponActor)->currentAmmoCount; + } + HeldWeapon->SetChildActorClass(PrimaryWeaponClass); + if (PreviousAmmoCount >= 0) + { + Cast(HeldWeapon->GetChildActor())->currentAmmoCount = PreviousAmmoCount; } PrimaryWeaponActor = HeldWeapon->GetChildActor(); PrimaryWeapon = Cast(PrimaryWeaponActor); @@ -609,10 +612,15 @@ void AEndlessVendettaCharacter::EquipSecondary() } if (SecondaryWeaponClass != nullptr) { - HeldWeapon->SetChildActorClass(SecondaryWeaponClass); + int PreviousAmmoCount = -1; if (SecondaryWeaponClass == SecondaryWeaponActor->GetClass()) { - Cast(HeldWeapon->GetChildActor())->currentAmmoCount = Cast(SecondaryWeaponActor)->currentAmmoCount; + PreviousAmmoCount = Cast(SecondaryWeaponActor)->currentAmmoCount; + } + HeldWeapon->SetChildActorClass(SecondaryWeaponClass); + if (PreviousAmmoCount >= 0) + { + Cast(HeldWeapon->GetChildActor())->currentAmmoCount = PreviousAmmoCount; } SecondaryWeaponActor = HeldWeapon->GetChildActor(); SecondaryWeapon = Cast(SecondaryWeaponActor);