More functionality moved to C++, allowing BugPlacerPawn to properly initialise and destroy itself.

This commit is contained in:
Jamie Greunbaum 2023-03-16 01:28:04 -04:00
parent dba5c7712a
commit 4aadcee90c
3 changed files with 35 additions and 2 deletions

Binary file not shown.

View File

@ -3,7 +3,9 @@
#include "BugPlacerPawn.h" #include "BugPlacerPawn.h"
#include "Components/SphereComponent.h" #include "Components/SphereComponent.h"
#include "GameFramework/Character.h"
#include "GameFramework/FloatingPawnMovement.h" #include "GameFramework/FloatingPawnMovement.h"
#include "Kismet/GameplayStatics.h"
ABugPlacerPawn::ABugPlacerPawn() ABugPlacerPawn::ABugPlacerPawn()
@ -27,10 +29,14 @@ ABugPlacerPawn::ABugPlacerPawn()
void ABugPlacerPawn::BeginPlay() void ABugPlacerPawn::BeginPlay()
{ {
Super::BeginPlay();
this->GetWorldSettings()->SetTimeDilation(this->GetWorldSettings()->MinGlobalTimeDilation); this->GetWorldSettings()->SetTimeDilation(this->GetWorldSettings()->MinGlobalTimeDilation);
this->CustomTimeDilation = 1.0f / this->GetWorldSettings()->MinGlobalTimeDilation; this->CustomTimeDilation = 1.0f / this->GetWorldSettings()->MinGlobalTimeDilation;
this->OriginalPlayer = UGameplayStatics::GetPlayerCharacter(this, 0);
this->Activate();
Super::BeginPlay();
} }
void ABugPlacerPawn::EndPlay(const EEndPlayReason::Type EndPlayReason) void ABugPlacerPawn::EndPlay(const EEndPlayReason::Type EndPlayReason)
@ -40,3 +46,18 @@ void ABugPlacerPawn::EndPlay(const EEndPlayReason::Type EndPlayReason)
Super::EndPlay(EndPlayReason); Super::EndPlay(EndPlayReason);
} }
void ABugPlacerPawn::Activate()
{
this->SavedMaxSpeed = this->PawnMovement->GetMaxSpeed();
UGameplayStatics::GetPlayerController(this, 0)->Possess(this);
}
void ABugPlacerPawn::Deactivate()
{
UGameplayStatics::GetPlayerController(this, 0)->Possess(this->OriginalPlayer);
this->Destroy();
}

View File

@ -19,10 +19,22 @@ public:
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
UFUNCTION(BlueprintCallable)
void Activate();
UFUNCTION(BlueprintCallable)
void Deactivate();
protected:
UPROPERTY(BlueprintReadWrite)
float SavedMaxSpeed = 0.0f;
private: private:
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true")) UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true"))
TObjectPtr<class USphereComponent> SphereComponent; TObjectPtr<class USphereComponent> SphereComponent;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true")) UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true"))
TObjectPtr<class UFloatingPawnMovement> PawnMovement; TObjectPtr<class UFloatingPawnMovement> PawnMovement;
TObjectPtr<class ACharacter> OriginalPlayer;
}; };