Bugfix Crash on Second Play Through
This commit is contained in:
parent
f239743e7f
commit
9b971d1ae9
@ -144,30 +144,11 @@ void ASeagullGameCharacter::StartGame()
|
|||||||
}
|
}
|
||||||
GetWorld()->GetTimerManager().SetTimer(GameTimerHandle, this, &ASeagullGameCharacter::EndGame, GameTime, false);
|
GetWorld()->GetTimerManager().SetTimer(GameTimerHandle, this, &ASeagullGameCharacter::EndGame, GameTime, false);
|
||||||
|
|
||||||
FTimerHandle CravingTimerHandle;
|
if (GetWorld()->GetTimerManager().IsTimerActive(CravingTimerHandle))
|
||||||
GetWorld()->GetTimerManager().SetTimer(CravingTimerHandle, [this]()
|
|
||||||
{
|
{
|
||||||
TSubclassOf<AItemActor> ItemActor = ItemActors[FMath::RandRange(0, ItemActors.Num() - 1)];
|
GetWorld()->GetTimerManager().ClearTimer(CravingTimerHandle);
|
||||||
if (IsValid(CravingItemActor)) CravingItemActor->Destroy();
|
}
|
||||||
CravingItemActor = GetWorld()->SpawnActor(ItemActor);
|
GetWorld()->GetTimerManager().SetTimer(CravingTimerHandle, this, &ASeagullGameCharacter::SetCravingItem, 60, true, 2);
|
||||||
CurrentCraving = Cast<AItemActor>(CravingItemActor)->ItemType;
|
|
||||||
CravingItemActor->SetActorEnableCollision(false);
|
|
||||||
if (!IsValid(John)) return;
|
|
||||||
UStaticMeshComponent* MeshComponent = Cast<UStaticMeshComponent>(John->GetComponentByClass(UStaticMeshComponent::StaticClass()));
|
|
||||||
if (!MeshComponent->HasAnySockets()) return;
|
|
||||||
CravingItemActor->AttachToComponent(MeshComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale, "CravingSocket");
|
|
||||||
FString CravingString = UEnum::GetValueAsString(CurrentCraving);
|
|
||||||
CravingString.Split(FString("::"), nullptr, &CravingString);
|
|
||||||
for (int i = 0; i < CravingString.Len(); i++)
|
|
||||||
{
|
|
||||||
if (CravingString[i] >= 'A' && CravingString[i] <= 'Z')
|
|
||||||
{
|
|
||||||
CravingString.InsertAt(i, " ");
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CravingItemName = CravingString;
|
|
||||||
}, 60, true, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASeagullGameCharacter::EndGame()
|
void ASeagullGameCharacter::EndGame()
|
||||||
@ -205,6 +186,30 @@ void ASeagullGameCharacter::Scroll(const FInputActionValue& Value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ASeagullGameCharacter::SetCravingItem()
|
||||||
|
{
|
||||||
|
const TSubclassOf<AItemActor> ItemActor = ItemActors[FMath::RandRange(0, ItemActors.Num() - 1)];
|
||||||
|
if (IsValid(CravingItemActor)) CravingItemActor->Destroy();
|
||||||
|
CravingItemActor = GetWorld()->SpawnActor(ItemActor);
|
||||||
|
CurrentCraving = Cast<AItemActor>(CravingItemActor)->ItemType;
|
||||||
|
CravingItemActor->SetActorEnableCollision(false);
|
||||||
|
if (!IsValid(John)) return;
|
||||||
|
UStaticMeshComponent* MeshComponent = Cast<UStaticMeshComponent>(John->GetComponentByClass(UStaticMeshComponent::StaticClass()));
|
||||||
|
if (!MeshComponent->HasAnySockets()) return;
|
||||||
|
CravingItemActor->AttachToComponent(MeshComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale, "CravingSocket");
|
||||||
|
FString CravingString = UEnum::GetValueAsString(CurrentCraving);
|
||||||
|
CravingString.Split(FString("::"), nullptr, &CravingString);
|
||||||
|
for (int i = 0; i < CravingString.Len(); i++)
|
||||||
|
{
|
||||||
|
if (CravingString[i] >= 'A' && CravingString[i] <= 'Z')
|
||||||
|
{
|
||||||
|
CravingString.InsertAt(i, " ");
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CravingItemName = CravingString;
|
||||||
|
}
|
||||||
|
|
||||||
void ASeagullGameCharacter::PickupItem()
|
void ASeagullGameCharacter::PickupItem()
|
||||||
{
|
{
|
||||||
OnPlayerPickupItem.Broadcast();
|
OnPlayerPickupItem.Broadcast();
|
||||||
|
@ -100,6 +100,8 @@ public:
|
|||||||
UFUNCTION(Category = "General")
|
UFUNCTION(Category = "General")
|
||||||
void Scroll(const FInputActionValue& Value);
|
void Scroll(const FInputActionValue& Value);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Item")
|
||||||
|
void SetCravingItem();
|
||||||
UFUNCTION(BlueprintCallable, Category = "Item")
|
UFUNCTION(BlueprintCallable, Category = "Item")
|
||||||
void PickupItem();
|
void PickupItem();
|
||||||
UFUNCTION(BlueprintCallable, Category = "Item")
|
UFUNCTION(BlueprintCallable, Category = "Item")
|
||||||
@ -126,6 +128,8 @@ public:
|
|||||||
FString CravingItemName;
|
FString CravingItemName;
|
||||||
UPROPERTY(BlueprintReadOnly, Category = "Item")
|
UPROPERTY(BlueprintReadOnly, Category = "Item")
|
||||||
FString HeldItemName;
|
FString HeldItemName;
|
||||||
|
UPROPERTY(BlueprintReadOnly, Category = "Item")
|
||||||
|
FTimerHandle CravingTimerHandle;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadOnly, Category = "John")
|
UPROPERTY(BlueprintReadOnly, Category = "John")
|
||||||
AActor* John;
|
AActor* John;
|
||||||
|
Loading…
Reference in New Issue
Block a user