Fixed Missing Ref when Quickly Switching Equipment
This commit is contained in:
parent
6cf1fc1869
commit
f2215f05e4
BIN
EndlessVendetta/Content/Gadgets/TestGadgets/RC_ExampleRecon.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Gadgets/TestGadgets/RC_ExampleRecon.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset
(Stored with Git LFS)
Binary file not shown.
@ -131,76 +131,120 @@ void AEndlessVendettaCharacter::ToggleCombat()
|
||||
//When 1 is pressed it calls EquipPrimary
|
||||
void AEndlessVendettaCharacter::EquipPrimary()
|
||||
{
|
||||
if (IsValid(PrimaryWeapon))
|
||||
{
|
||||
PrimaryWeapon->Destroy();
|
||||
PrimaryWeapon = nullptr;
|
||||
bHasRifle = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsValid(SecondaryWeapon)) EquipSecondary();
|
||||
|
||||
// Marcel I respect you, like you and what not, please for the love of god don't touch these two guard clauses
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;/////////////////////////
|
||||
if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;///////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
|
||||
bHasRifle = true;
|
||||
//Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
||||
AActor* PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
//Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object
|
||||
//We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor
|
||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||
|
||||
//If primary weapon is not there but secondary weapon is it will call equipSecondary.
|
||||
//EquipSecondary checks and sees that secondary is there so it will call to destroy itself
|
||||
//Code goes back and sees primary weapon is not there anymore and spawns it in.
|
||||
//Same thing for the EquipSecondary()
|
||||
if (!IsValid(PrimaryWeapon))
|
||||
{
|
||||
if (IsValid(SecondaryWeapon)) EquipSecondary();
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("Primary equipped"));
|
||||
bHasRifle = true;
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
//Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
||||
AActor* PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
//Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object
|
||||
//We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor
|
||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||
|
||||
}
|
||||
else if (IsValid(PrimaryWeapon))
|
||||
{
|
||||
PrimaryWeapon->Destroy();
|
||||
bHasRifle = false;
|
||||
|
||||
}
|
||||
|
||||
// if (!IsValid(PrimaryWeapon))
|
||||
// {
|
||||
// if (IsValid(SecondaryWeapon)) EquipSecondary();
|
||||
//
|
||||
// UE_LOG(LogTemp, Display, TEXT("Primary equipped"));
|
||||
// bHasRifle = true;
|
||||
// FActorSpawnParameters spawnParams;
|
||||
// spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
// FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
// //Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
||||
// AActor* PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||
// PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
// //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object
|
||||
// //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor
|
||||
// PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||
//
|
||||
// }
|
||||
// else if (IsValid(PrimaryWeapon))
|
||||
// {
|
||||
// PrimaryWeapon->Destroy();
|
||||
// bHasRifle = false;
|
||||
// }
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::EquipSecondary()
|
||||
{
|
||||
if (IsValid(SecondaryWeapon))
|
||||
{
|
||||
SecondaryWeapon->Destroy();
|
||||
SecondaryWeapon = nullptr;
|
||||
bHasRifle = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsValid(PrimaryWeapon)) EquipPrimary();
|
||||
|
||||
// Marcel I respect you, like you and what not, please for the love of god don't touch these two guard clauses
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;/////////////////////////
|
||||
if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;///////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!IsValid(SecondaryWeapon))
|
||||
{
|
||||
if (IsValid(PrimaryWeapon)) EquipPrimary();
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("Secondary equipped"));
|
||||
bHasRifle = true;
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
AActor* SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);
|
||||
SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
|
||||
}
|
||||
else if (IsValid(SecondaryWeapon))
|
||||
{
|
||||
SecondaryWeapon->Destroy();
|
||||
bHasRifle = false;
|
||||
}
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
|
||||
bHasRifle = true;
|
||||
AActor* SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);
|
||||
SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
|
||||
|
||||
// if (!IsValid(SecondaryWeapon))
|
||||
// {
|
||||
// if (IsValid(PrimaryWeapon)) EquipPrimary();
|
||||
//
|
||||
// UE_LOG(LogTemp, Display, TEXT("Secondary equipped"));
|
||||
// bHasRifle = true;
|
||||
// FActorSpawnParameters spawnParams;
|
||||
// spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
// FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
// AActor* SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);
|
||||
// SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||
// SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
|
||||
// }
|
||||
// else if (IsValid(SecondaryWeapon))
|
||||
// {
|
||||
// SecondaryWeapon->Destroy();
|
||||
// bHasRifle = false;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
//Calls the fire function in the baseWeaponClass
|
||||
void AEndlessVendettaCharacter::TapFireCaller()
|
||||
{
|
||||
if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon))
|
||||
{
|
||||
PrimaryWeaponClass.GetDefaultObject()->TapFire();
|
||||
}
|
||||
UE_LOG(LogTemp, Warning, TEXT("Tap Fire"));
|
||||
// if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon))
|
||||
// {
|
||||
// PrimaryWeaponClass.GetDefaultObject()->TapFire();
|
||||
// }
|
||||
}
|
||||
|
||||
//POTENTIAL PICKUP SYSTEM NEEDS CHANGING BUT YES
|
||||
|
@ -56,19 +56,13 @@ public:
|
||||
|
||||
bool TryToUnequipRecon()
|
||||
{
|
||||
if (ReconGadget->Equipped)
|
||||
{
|
||||
return ReconGadget->Unequip();
|
||||
}
|
||||
if (ReconGadget->Equipped) return ReconGadget->Unequip();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TryToUnequipCombat()
|
||||
{
|
||||
if (CombatGadget->Equipped)
|
||||
{
|
||||
return CombatGadget->Unequip();
|
||||
}
|
||||
if (CombatGadget->Equipped) return CombatGadget->Unequip();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user