Bugfix Held Weapon Actor Pending to be Destroyed

This commit is contained in:
Philip W 2024-05-12 22:55:23 +01:00
parent 1873777770
commit ec4b8c46b3

View File

@ -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<ABaseWeaponClass>(HeldWeapon->GetChildActor())->currentAmmoCount = Cast<ABaseWeaponClass>(PrimaryWeaponActor)->currentAmmoCount;
PreviousAmmoCount = Cast<ABaseWeaponClass>(PrimaryWeaponActor)->currentAmmoCount;
}
HeldWeapon->SetChildActorClass(PrimaryWeaponClass);
if (PreviousAmmoCount >= 0)
{
Cast<ABaseWeaponClass>(HeldWeapon->GetChildActor())->currentAmmoCount = PreviousAmmoCount;
}
PrimaryWeaponActor = HeldWeapon->GetChildActor();
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
@ -609,10 +612,15 @@ void AEndlessVendettaCharacter::EquipSecondary()
}
if (SecondaryWeaponClass != nullptr)
{
HeldWeapon->SetChildActorClass(SecondaryWeaponClass);
int PreviousAmmoCount = -1;
if (SecondaryWeaponClass == SecondaryWeaponActor->GetClass())
{
Cast<ABaseWeaponClass>(HeldWeapon->GetChildActor())->currentAmmoCount = Cast<ABaseWeaponClass>(SecondaryWeaponActor)->currentAmmoCount;
PreviousAmmoCount = Cast<ABaseWeaponClass>(SecondaryWeaponActor)->currentAmmoCount;
}
HeldWeapon->SetChildActorClass(SecondaryWeaponClass);
if (PreviousAmmoCount >= 0)
{
Cast<ABaseWeaponClass>(HeldWeapon->GetChildActor())->currentAmmoCount = PreviousAmmoCount;
}
SecondaryWeaponActor = HeldWeapon->GetChildActor();
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);