Bugfix No Post Processing Volume Crashes Engine

This commit is contained in:
Philip W 2023-02-23 01:28:29 +00:00
parent c880eb27ac
commit 985e713659

View File

@ -22,7 +22,6 @@ ATempCharacter::ATempCharacter()
GoldBalance = GoldBalance;
Health = Health;
this->GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
}
// Called when the game starts or when spawned
@ -36,8 +35,11 @@ void ATempCharacter::BeginPlay()
//MAKE SURE POST PROCESSING IS IN THE SCENE OR GAME WILL CRASH
UGameplayStatics::GetAllActorsOfClass(GetWorld(), APostProcessVolume::StaticClass(), AllActorsInScene);
PostProcessVolume = Cast<APostProcessVolume>(AllActorsInScene[0]);
if (ensureMsgf(AllActorsInScene.Num() > 0, TEXT("No Post Processing Volume in scene")))
{
PostProcessVolume = Cast<APostProcessVolume>(AllActorsInScene[0]);
}
Enemy = TEXT("Enemy");
UGameplayStatics::GetAllActorsWithTag(GetWorld(), Enemy, AIActors);
@ -49,6 +51,7 @@ void ATempCharacter::ForwardInput(float Axis)
{
AddMovementInput(UKismetMathLibrary::GetForwardVector(FRotator(0, GetControlRotation().Yaw, 0)) * Axis);
}
//Binds the input we made in the setup player component to the right vector
void ATempCharacter::RightMoveInput(float Axis)
{
@ -61,7 +64,7 @@ void ATempCharacter::Sneak()
if (bIsCrouched)
{
UnCrouch();
PostProcessVolume->Settings.VignetteIntensity = 0.0f;
if (PostProcessVolume != nullptr) PostProcessVolume->Settings.VignetteIntensity = 0.0f;
for (AActor* Actor : AIActors)
{
USphereComponent* SphereComponent = Actor->FindComponentByClass<USphereComponent>();
@ -82,9 +85,8 @@ void ATempCharacter::Sneak()
SphereComponent->SetSphereRadius(15.0f);
}
}
PostProcessVolume->Settings.VignetteIntensity = 0.8f;
if (PostProcessVolume != nullptr) PostProcessVolume->Settings.VignetteIntensity = 0.8f;
}
}
@ -115,7 +117,6 @@ void ATempCharacter::KeyPressed()
}
// Line trace logic
void ATempCharacter::LineTraceLogic()
{
@ -128,37 +129,37 @@ void ATempCharacter::LineTraceLogic()
FCollisionQueryParams TraceParams;
TraceParams.AddIgnoredActor(this);
bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
if (bHit)
{
//we store the GetItem function from InventoryComponent into ItemArray variable
if(OutHit.GetActor() == nullptr)
if (OutHit.GetActor() == nullptr)
{
return;
}
if(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
if (OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
{
UE_LOG(LogTemp, Display, TEXT("Hit Merchant"));
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
if(GoldBalance >= ItemArray->ItemCostPrice)
if (GoldBalance >= ItemArray->ItemCostPrice)
{
GoldBalance -= ItemArray->ItemCostPrice;
Inventory->AddItem(ItemArray);
UE_LOG(LogTemp, Display, TEXT("Item Purchased"));
}
if(GoldBalance <= 0)
if (GoldBalance <= 0)
{
UE_LOG(LogTemp, Display, TEXT("Not Enough Gold"));
}
if(OutHit.GetActor()->ActorHasTag(Ammo))
if (OutHit.GetActor()->ActorHasTag(Ammo))
{
OutHit.GetActor()->Destroy();
}
}
// if the actor hit has the interaction component/script then it will activate the code
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
{
if (MyInteractable->ShopDialogWidget->IsVisible())
@ -207,7 +208,7 @@ void ATempCharacter::InputDisabler()
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeUIOnly());
PlayerController->bShowMouseCursor = true;
disableTab = true;
if (ThisCamera != nullptr)
{
@ -229,7 +230,7 @@ void ATempCharacter::InputEnabler()
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeGameOnly());
PlayerController->bShowMouseCursor = false;
UE_LOG(LogTemp, Display, TEXT("Enabling Inputs"));
disableTab = true;
TraceDistance = 300;
@ -244,7 +245,7 @@ void ATempCharacter::InputEnabler()
void ATempCharacter::UseItem(class UBaseItem* Item)
{
if(Item)
if (Item)
{
Item->Use(this);
Item->OnUse(this); //OnUse is a Blueprint Version
@ -257,7 +258,3 @@ void ATempCharacter::BuyItem()
TraceDistance = 1000;
LineTraceLogic();
}