From ec4b8c46b320377c391e1570f9c227b275a899dd Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Sun, 12 May 2024 22:55:23 +0100 Subject: [PATCH] Bugfix Held Weapon Actor Pending to be Destroyed --- .../EndlessVendettaCharacter.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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);