Bug Fixed Mining crashing the game
When pressing E on the crystals it kept on crashing due to destroy being executed before pointer checks
This commit is contained in:
parent
fc25c8adf0
commit
4ad0959f08
@ -26,7 +26,6 @@ ATempCharacter::ATempCharacter()
|
|||||||
void ATempCharacter::BeginPlay()
|
void ATempCharacter::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
FirstPlayerController = GetWorld()->GetFirstPlayerController();
|
FirstPlayerController = GetWorld()->GetFirstPlayerController();
|
||||||
CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
|
CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
|
||||||
WidgetPointer = Cast<UWidgetInteractionComponent>(this->GetComponentByClass(UWidgetInteractionComponent::StaticClass()));
|
WidgetPointer = Cast<UWidgetInteractionComponent>(this->GetComponentByClass(UWidgetInteractionComponent::StaticClass()));
|
||||||
@ -136,7 +135,6 @@ void ATempCharacter::LineTraceLogic()
|
|||||||
{
|
{
|
||||||
//UE_LOG(LogTemp, Display, TEXT("LineTraceLogic activated"));
|
//UE_LOG(LogTemp, Display, TEXT("LineTraceLogic activated"));
|
||||||
float GlobalTrace = TraceDistance;
|
float GlobalTrace = TraceDistance;
|
||||||
FHitResult OutHit;
|
|
||||||
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
|
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
|
||||||
FVector Start = ThisCamera->GetComponentLocation();
|
FVector Start = ThisCamera->GetComponentLocation();
|
||||||
FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector();
|
FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector();
|
||||||
@ -149,24 +147,28 @@ void ATempCharacter::LineTraceLogic()
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(OutHit.GetActor()->ActorHasTag(TEXT("Probertium")))
|
||||||
|
{
|
||||||
|
AddToInventory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(OutHit.GetActor()->ActorHasTag(TEXT("Iroquid")))
|
||||||
|
{
|
||||||
|
AddToInventory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (OutHit.GetActor()->ActorHasTag(TEXT("Azos")))
|
||||||
|
{
|
||||||
|
AddToInventory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (OutHit.GetActor()->ActorHasTag(TEXT("Eis")))
|
||||||
|
{
|
||||||
|
AddToInventory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
|
if (OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
|
||||||
{
|
{
|
||||||
if(OutHit.GetActor()->ActorHasTag(TEXT("Probertium")))
|
|
||||||
{
|
|
||||||
OutHit.GetActor()->Destroy();
|
|
||||||
}
|
|
||||||
else if(OutHit.GetActor()->ActorHasTag(TEXT("Iroquid")))
|
|
||||||
{
|
|
||||||
OutHit.GetActor()->Destroy();
|
|
||||||
}
|
|
||||||
else if (OutHit.GetActor()->ActorHasTag(TEXT("Azos")))
|
|
||||||
{
|
|
||||||
OutHit.GetActor()->Destroy();
|
|
||||||
}
|
|
||||||
else if (OutHit.GetActor()->ActorHasTag(TEXT("Eis")))
|
|
||||||
{
|
|
||||||
OutHit.GetActor()->Destroy();
|
|
||||||
}
|
|
||||||
UE_LOG(LogTemp, Display, TEXT("Hit Merchant"));
|
UE_LOG(LogTemp, Display, TEXT("Hit Merchant"));
|
||||||
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
|
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
|
||||||
if (GoldBalance >= ItemArray->ItemCostPrice)
|
if (GoldBalance >= ItemArray->ItemCostPrice)
|
||||||
@ -219,6 +221,26 @@ void ATempCharacter::LineTraceLogic()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ATempCharacter::AddToInventory()
|
||||||
|
{
|
||||||
|
if (OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Hit Merchant"));
|
||||||
|
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
|
||||||
|
if (GoldBalance >= ItemArray->ItemCostPrice)
|
||||||
|
{
|
||||||
|
GoldBalance -= ItemArray->ItemCostPrice;
|
||||||
|
Inventory->AddItem(ItemArray);
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Item Purchased"));
|
||||||
|
}
|
||||||
|
if (GoldBalance <= 0)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Not Enough Gold"));
|
||||||
|
}
|
||||||
|
OutHit.GetActor()->Destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ATempCharacter::InputDisabler()
|
void ATempCharacter::InputDisabler()
|
||||||
{
|
{
|
||||||
//Disable Character Movement
|
//Disable Character Movement
|
||||||
|
@ -128,5 +128,11 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, Category= "Widgets")
|
UPROPERTY(EditAnywhere, Category= "Widgets")
|
||||||
TSubclassOf<UUserWidget> CrossHairSub;
|
TSubclassOf<UUserWidget> CrossHairSub;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
FHitResult OutHit;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void AddToInventory();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user