From 7253ddec95426b242b3beae04e70cbc7bd6e4f54 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 7 Mar 2021 02:35:12 -0500 Subject: [PATCH] Move these to ActorSpawningPlugin --- .../Private/SpawnableActor.cpp | 92 ---------- .../Private/SpawnableSkeletalMeshActor.cpp | 39 ---- .../Private/SpawnableStaticMeshActor.cpp | 27 --- .../Private/SpawningActor.cpp | 171 ------------------ .../EventCenterPlugin/Public/SpawnableActor.h | 57 ------ .../Public/SpawnableSkeletalMeshActor.h | 38 ---- .../Public/SpawnableStaticMeshActor.h | 38 ---- .../EventCenterPlugin/Public/SpawningActor.h | 55 ------ 8 files changed, 517 deletions(-) delete mode 100644 Source/EventCenterPlugin/Private/SpawnableActor.cpp delete mode 100644 Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp delete mode 100644 Source/EventCenterPlugin/Private/SpawnableStaticMeshActor.cpp delete mode 100644 Source/EventCenterPlugin/Private/SpawningActor.cpp delete mode 100644 Source/EventCenterPlugin/Public/SpawnableActor.h delete mode 100644 Source/EventCenterPlugin/Public/SpawnableSkeletalMeshActor.h delete mode 100644 Source/EventCenterPlugin/Public/SpawnableStaticMeshActor.h delete mode 100644 Source/EventCenterPlugin/Public/SpawningActor.h diff --git a/Source/EventCenterPlugin/Private/SpawnableActor.cpp b/Source/EventCenterPlugin/Private/SpawnableActor.cpp deleted file mode 100644 index ca38bd6..0000000 --- a/Source/EventCenterPlugin/Private/SpawnableActor.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "SpawnableActor.h" - -#include "UObject/Object.h" - -DEFINE_LOG_CATEGORY(SpawnableActorLog); - -ASpawnableActor::ASpawnableActor() -{ - UE_LOG(SpawnableActorLog, Log, TEXT("CTOR()")); - - // Set this actor to call Tick() every frame. - // You can turn this off to improve performance if you don't need it. - PrimaryActorTick.bCanEverTick = true; - - /* - // Attach a mesh to the object. - static ConstructorHelpers::FObjectFinder BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'")); - - BaseMesh = BaseMeshAsset.Object; - - BaseMeshComponent = CreateDefaultSubobject(TEXT("BaseMesh")); - BaseMeshComponent->SetupAttachment(RootComponent); - - BaseMeshComponent->SetStaticMesh(BaseMesh); - - BaseMeshComponent->SetSimulatePhysics(true); - */ - - // NB: Only valid to call in the CTOR. - //BaseMeshComponent = CreateDefaultSubobject(TEXT("BaseMesh")); - //BaseMeshComponent->SetupAttachment(RootComponent); - - // Attach a mesh to the object to try to turn on physics. - // Maybe not necessary... - //static ConstructorHelpers::FObjectFinder BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'")); - //BaseMeshComponent->SetStaticMesh(BaseMeshAsset.Object); - //BaseMeshComponent->SetSimulatePhysics(true); -} - -ASpawnableActor::~ASpawnableActor() -{ -} - -void ASpawnableActor::BeginPlay() -{ - Super::BeginPlay(); -} - -void ASpawnableActor::BeginDestroy() -{ - Super::BeginDestroy(); -} - -void ASpawnableActor::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); -} - -// TODO: This doesn't work outside of constructor -/*void ASpawnableActor::SetMeshByString(const FString& meshName) -{ - // Attach a mesh to the object. - // eg. TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'") - static ConstructorHelpers::FObjectFinder BaseMeshAsset(*meshName); - - BaseMesh = BaseMeshAsset.Object; - - BaseMeshComponent = CreateDefaultSubobject(TEXT("BaseMesh")); - - BaseMeshComponent->SetStaticMesh(BaseMesh); - - BaseMeshComponent->SetSimulatePhysics(true); -}*/ - -// Works!! -/*void ASpawnableActor::SetMesh(UStaticMesh* staticMesh) -{ - BaseMesh = staticMesh; - BaseMeshComponent->SetStaticMesh(BaseMesh); - BaseMeshComponent->SetSimulatePhysics(true); - BaseMeshComponent->UpdateCollisionFromStaticMesh(); -}*/ - -void ASpawnableActor::StartDestroyTimer(float seconds) -{ - GetWorldTimerManager().SetTimer(DestroyTimer, this, &ASpawnableActor::InvokeDestroy, seconds); -} - -void ASpawnableActor::InvokeDestroy() -{ - Destroy(); -} diff --git a/Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp b/Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp deleted file mode 100644 index 5a5c896..0000000 --- a/Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "SpawnableSkeletalMeshActor.h" - -#include "UObject/Object.h" -#include "Engine/EngineTypes.h" - - -DEFINE_LOG_CATEGORY(SpawnableSkeletalMeshActorLog); - -ASpawnableSkeletalMeshActor::ASpawnableSkeletalMeshActor() -{ - UE_LOG(SpawnableSkeletalMeshActorLog, Log, TEXT("CTOR")); - - // Set this actor to call Tick() every frame. - // You can turn this off to improve performance if you don't need it. - PrimaryActorTick.bCanEverTick = true; - - BaseMeshComponent = CreateDefaultSubobject(TEXT("BaseMesh")); - RootComponent = BaseMeshComponent; - BaseMeshComponent->SetupAttachment(RootComponent); -} - -ASpawnableSkeletalMeshActor::~ASpawnableSkeletalMeshActor() { -} - -void ASpawnableSkeletalMeshActor::SetSpawnableSkeletalMesh(USkeletalMesh* skeletalMesh) -{ - UE_LOG(SpawnableSkeletalMeshActorLog, Log, TEXT("SetSpawnableSkeletalMesh()")); - - BaseMesh = skeletalMesh; - - BaseMeshComponent->SetSkeletalMesh(BaseMesh); - - BaseMeshComponent->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody); - BaseMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); - BaseMeshComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block); - - BaseMeshComponent->SetSimulatePhysics(true); -} - diff --git a/Source/EventCenterPlugin/Private/SpawnableStaticMeshActor.cpp b/Source/EventCenterPlugin/Private/SpawnableStaticMeshActor.cpp deleted file mode 100644 index 231ddda..0000000 --- a/Source/EventCenterPlugin/Private/SpawnableStaticMeshActor.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "SpawnableStaticMeshActor.h" - -#include "UObject/Object.h" - -DEFINE_LOG_CATEGORY(SpawnableStaticMeshActorLog); - -ASpawnableStaticMeshActor::ASpawnableStaticMeshActor() -{ - // Set this actor to call Tick() every frame. - // You can turn this off to improve performance if you don't need it. - PrimaryActorTick.bCanEverTick = true; - - BaseMeshComponent = CreateDefaultSubobject(TEXT("BaseMesh")); - BaseMeshComponent->SetupAttachment(RootComponent); -} - -ASpawnableStaticMeshActor::~ASpawnableStaticMeshActor() { -} - -void ASpawnableStaticMeshActor::SetSpawnableStaticMesh(UStaticMesh* staticMesh) -{ - BaseMesh = staticMesh; - BaseMeshComponent->SetStaticMesh(BaseMesh); - BaseMeshComponent->SetSimulatePhysics(true); - BaseMeshComponent->UpdateCollisionFromStaticMesh(); -} - diff --git a/Source/EventCenterPlugin/Private/SpawningActor.cpp b/Source/EventCenterPlugin/Private/SpawningActor.cpp deleted file mode 100644 index 2ffe4bc..0000000 --- a/Source/EventCenterPlugin/Private/SpawningActor.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include "SpawningActor.h" - -#include "SpawnableActor.h" - -#include "Engine/World.h" -#include "UObject/Object.h" -#include "Math/UnrealMathUtility.h" - - -DEFINE_LOG_CATEGORY(SpawningActorLog); - -ASpawningActor::ASpawningActor() -{ - UE_LOG(EventSourceLog, Log, TEXT("CTOR()")); - - // Set this actor to call Tick() every frame. - // You can turn this off to improve performance if you don't need it. - PrimaryActorTick.bCanEverTick = true; -} - -ASpawningActor::~ASpawningActor() -{ -} - -void ASpawningActor::BeginPlay() -{ - Super::BeginPlay(); -} - -void ASpawningActor::BeginDestroy() -{ - Super::BeginDestroy(); -} - -void ASpawningActor::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); -} - -ASpawnableActor* ASpawningActor::Spawn() -{ - // Spawn actor - // TODO(bt): This will memory leak. - ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass()); - - // Get player location - FVector playerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation(); - - - // Teleport actor randomly - // TODO(bt): Put this in front of the camera, or on the (camera -> player) arc! - float x = FMath::RandRange(-4000.0f, 4000.0f); - float y = FMath::RandRange(-4000.0f, 4000.0f); - float z = FMath::RandRange(3000.0f, 10000.0f); - - FVector location( - playerLocation.X + x, - playerLocation.Y + y, - playerLocation.Z + z - ); - - FRotator rotation; - spawnedActor->SetActorLocationAndRotation( - location, - rotation, - false, - 0, - ETeleportType::ResetPhysics - ); - - // We don't want to keep the actor around indefinitely since they may pile up unused. - // Optionally, we could maintain a queue and cull the oldest actors. - spawnedActor->StartDestroyTimer(100.0); - - return spawnedActor; -} - -ASpawnableStaticMeshActor* ASpawningActor::SpawnStaticMeshActor() -{ - // Spawn actor - // TODO(bt): This will memory leak. - ASpawnableStaticMeshActor* spawnedActor = (ASpawnableStaticMeshActor*)GetWorld()->SpawnActor(ASpawnableStaticMeshActor::StaticClass()); - - // Get player location - FVector playerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation(); - - - // Teleport actor randomly - // TODO(bt): Put this in front of the camera, or on the (camera -> player) arc! - float x = FMath::RandRange(-4000.0f, 4000.0f); - float y = FMath::RandRange(-4000.0f, 4000.0f); - float z = FMath::RandRange(3000.0f, 10000.0f); - - FVector location( - playerLocation.X + x, - playerLocation.Y + y, - playerLocation.Z + z - ); - - FRotator rotation; - spawnedActor->SetActorLocationAndRotation( - location, - rotation, - false, - 0, - ETeleportType::ResetPhysics - ); - - // We don't want to keep the actor around indefinitely since they may pile up unused. - // Optionally, we could maintain a queue and cull the oldest actors. - spawnedActor->StartDestroyTimer(100.0); - - return spawnedActor; -} - -ASpawnableSkeletalMeshActor* ASpawningActor::SpawnSkeletalMeshActor() -{ - FActorSpawnParameters actorSpawnParams; - actorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - - // Spawn actor - // TODO(bt): This will memory leak. - //ASpawnableSkeletalMeshActor* spawnedActor = - // (ASpawnableSkeletalMeshActor*)GetWorld()->SpawnActor(ASpawnableSkeletalMeshActor::StaticClass()); - - // Get player location - FVector playerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation(); - - // Teleport actor randomly - // TODO(bt): Put this in front of the camera, or on the (camera -> player) arc! - float x = FMath::RandRange(-4000.0f, 4000.0f); - float y = FMath::RandRange(-4000.0f, 4000.0f); - float z = FMath::RandRange(3000.0f, 10000.0f); - - FVector location( - playerLocation.X + x, - playerLocation.Y + y, - playerLocation.Z + z - ); - - FRotator rotation; - /*spawnedActor->SetActorLocationAndRotation( - location, - rotation, - false, - 0, - ETeleportType::ResetPhysics - );*/ - - ASpawnableSkeletalMeshActor* spawnedActor = - (ASpawnableSkeletalMeshActor*)GetWorld()->SpawnActor( - ASpawnableSkeletalMeshActor::StaticClass(), - &location, - &rotation, - actorSpawnParams - ); - - // We don't want to keep the actor around indefinitely since they may pile up unused. - // Optionally, we could maintain a queue and cull the oldest actors. - spawnedActor->StartDestroyTimer(100.0); - - return spawnedActor; -} - -void ASpawningActor::SpawnCallback(FString Channel, FString Message) -{ - UE_LOG(EventSourceLog, Log, TEXT("SpawnCallback()")); - - Spawn(); -} - diff --git a/Source/EventCenterPlugin/Public/SpawnableActor.h b/Source/EventCenterPlugin/Public/SpawnableActor.h deleted file mode 100644 index 7ac46fe..0000000 --- a/Source/EventCenterPlugin/Public/SpawnableActor.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -// Unreal Core -#include "CoreMinimal.h" -#include "UObject/NoExportTypes.h" -#include "Engine/EngineTypes.h" - -// EventCenterPlugin -#include "SpawnableActor.generated.h" - -DECLARE_LOG_CATEGORY_EXTERN(SpawnableActorLog, Log, All); - -// NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes. -UCLASS() -class EVENTCENTERPLUGIN_API ASpawnableActor : public AActor -{ - GENERATED_BODY() - -public: - - ASpawnableActor(); - ~ASpawnableActor(); - - /** Mesh to use */ - //UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true")) - //class UStaticMeshComponent* BaseMeshComponent; - - /** Mesh to use */ - //UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true")) - //class UStaticMesh* BaseMesh; - - // FIXME: This won't work outside of the ctor :( - //UFUNCTION(BlueprintCallable, Category = "SpawnableActor") - //void SetMeshByString(const FString& meshName); - - //UFUNCTION(BlueprintCallable, Category = "SpawnableActor") - //void SetMesh(UStaticMesh* staticMesh); - - /** Set a timer to destroy this actor. */ - void StartDestroyTimer(float seconds); - -protected: - // Called when the game starts or when spawned - virtual void BeginPlay() override; - - virtual void BeginDestroy() override; - - // Destroy timer callback. - void InvokeDestroy(); - - // (Optional) destroy callback timer. - FTimerHandle DestroyTimer; - -public: - // Called every frame - virtual void Tick(float DeltaTime) override; -}; diff --git a/Source/EventCenterPlugin/Public/SpawnableSkeletalMeshActor.h b/Source/EventCenterPlugin/Public/SpawnableSkeletalMeshActor.h deleted file mode 100644 index 856978e..0000000 --- a/Source/EventCenterPlugin/Public/SpawnableSkeletalMeshActor.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -// Unreal Core -#include "CoreMinimal.h" -#include "UObject/NoExportTypes.h" -#include "Engine/EngineTypes.h" - -// EventCenterPlugin -#include "SpawnableActor.h" -#include "SpawnableSkeletalMeshActor.generated.h" - -DECLARE_LOG_CATEGORY_EXTERN(SpawnableSkeletalMeshActorLog, Log, All); - -// NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes. -UCLASS() -class EVENTCENTERPLUGIN_API ASpawnableSkeletalMeshActor : public ASpawnableActor -{ - GENERATED_BODY() - -public: - - ASpawnableSkeletalMeshActor(); - ~ASpawnableSkeletalMeshActor(); - - /** Access to the skeletal mesh component */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableSkeletalMeshActor", meta = (AllowPrivateAccess = "true")) - class USkeletalMeshComponent* BaseMeshComponent; - - /** Set the skeletal mesh. */ - UFUNCTION(BlueprintCallable, Category = "SpawnableSkeletalMeshActor") - void SetSpawnableSkeletalMesh(USkeletalMesh* skeletalMesh); - -private: - /** Mesh to use */ - //UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true")) - class USkeletalMesh* BaseMesh; -}; - diff --git a/Source/EventCenterPlugin/Public/SpawnableStaticMeshActor.h b/Source/EventCenterPlugin/Public/SpawnableStaticMeshActor.h deleted file mode 100644 index 939f0e3..0000000 --- a/Source/EventCenterPlugin/Public/SpawnableStaticMeshActor.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -// Unreal Core -#include "CoreMinimal.h" -#include "UObject/NoExportTypes.h" -#include "Engine/EngineTypes.h" - -// EventCenterPlugin -#include "SpawnableActor.h" -#include "SpawnableStaticMeshActor.generated.h" - -DECLARE_LOG_CATEGORY_EXTERN(SpawnableStaticMeshActorLog, Log, All); - -// NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes. -UCLASS() -class EVENTCENTERPLUGIN_API ASpawnableStaticMeshActor : public ASpawnableActor -{ - GENERATED_BODY() - -public: - - ASpawnableStaticMeshActor(); - ~ASpawnableStaticMeshActor(); - - /** Access to the static mesh component */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableStaticMeshActor", meta = (AllowPrivateAccess = "true")) - class UStaticMeshComponent* BaseMeshComponent; - - /** Set the static mesh. */ - UFUNCTION(BlueprintCallable, Category = "SpawnableStaticMeshActor") - void SetSpawnableStaticMesh(UStaticMesh* staticMesh); - -private: - /** Mesh to use */ - //UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true")) - class UStaticMesh* BaseMesh; -}; - diff --git a/Source/EventCenterPlugin/Public/SpawningActor.h b/Source/EventCenterPlugin/Public/SpawningActor.h deleted file mode 100644 index 308cfdf..0000000 --- a/Source/EventCenterPlugin/Public/SpawningActor.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -// Unreal Core -#include "CoreMinimal.h" -#include "UObject/NoExportTypes.h" - -// EventCenterPlugin -#include "SpawnableActor.h" -#include "SpawnableSkeletalMeshActor.h" -#include "SpawnableStaticMeshActor.h" -#include "SpawningActor.generated.h" - -DECLARE_LOG_CATEGORY_EXTERN(SpawningActorLog, Log, All); - -// NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes. -UCLASS() -class EVENTCENTERPLUGIN_API ASpawningActor : public AActor -{ - GENERATED_BODY() - -public: - - ASpawningActor(); - ~ASpawningActor(); - - /** Create actor. */ - UFUNCTION(BlueprintCallable, Category = "SpawningActor") - ASpawnableActor* Spawn(); - - /** Create actor. */ - UFUNCTION(BlueprintCallable, Category = "SpawningActor") - ASpawnableStaticMeshActor* SpawnStaticMeshActor(); - - /** Create actor. */ - UFUNCTION(BlueprintCallable, Category = "SpawningActor") - ASpawnableSkeletalMeshActor* SpawnSkeletalMeshActor(); - - /** Create actor with delegation callback. */ - UFUNCTION(BlueprintCallable, Category = "SpawningActor") - void SpawnCallback(FString Channel, FString Message); - - /** Mesh to use */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true")) - class UStaticMeshComponent* BaseMesh; - -protected: - // Called when the game starts or when spawned - virtual void BeginPlay() override; - - virtual void BeginDestroy() override; - -public: - // Called every frame - virtual void Tick(float DeltaTime) override; -};