mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
spawn and attach a mesh (not proven to work yet!)
This commit is contained in:
@@ -12,6 +12,7 @@ ASpawnableActor::ASpawnableActor()
|
||||
// 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<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));
|
||||
|
||||
@@ -23,6 +24,11 @@ ASpawnableActor::ASpawnableActor()
|
||||
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
||||
|
||||
BaseMeshComponent->SetSimulatePhysics(true);
|
||||
*/
|
||||
|
||||
// NB: Only valid to call in the CTOR.
|
||||
BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
||||
BaseMeshComponent->SetupAttachment(RootComponent);
|
||||
}
|
||||
|
||||
ASpawnableActor::~ASpawnableActor()
|
||||
@@ -44,6 +50,28 @@ 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<UStaticMesh> BaseMeshAsset(*meshName);
|
||||
|
||||
BaseMesh = BaseMeshAsset.Object;
|
||||
|
||||
BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
||||
|
||||
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
||||
|
||||
BaseMeshComponent->SetSimulatePhysics(true);
|
||||
}
|
||||
|
||||
void ASpawnableActor::SetMesh(UStaticMesh* staticMesh)
|
||||
{
|
||||
BaseMesh = staticMesh;
|
||||
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
||||
BaseMeshComponent->SetSimulatePhysics(true);
|
||||
}
|
||||
|
||||
void ASpawnableActor::StartDestroyTimer(float seconds)
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@ void ASpawningActor::Tick(float DeltaTime)
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
void ASpawningActor::Spawn()
|
||||
ASpawnableActor* ASpawningActor::Spawn()
|
||||
{
|
||||
// Spawn actor
|
||||
// TODO(bt): This will memory leak.
|
||||
@@ -56,6 +56,8 @@ void ASpawningActor::Spawn()
|
||||
// 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(10.0);
|
||||
|
||||
return spawnedActor;
|
||||
}
|
||||
|
||||
void ASpawningActor::SpawnCallback(FString Channel, FString Message)
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "UObject/Interface.h"
|
||||
|
||||
|
||||
|
||||
#include "EventHandlerInterface.generated.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,13 @@ public:
|
||||
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);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "UObject/NoExportTypes.h"
|
||||
|
||||
// EventCenterPlugin
|
||||
#include "SpawnableActor.h"
|
||||
#include "SpawningActor.generated.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(SpawningActorLog, Log, All);
|
||||
@@ -22,7 +23,7 @@ public:
|
||||
|
||||
/** Create actor. */
|
||||
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||
void Spawn();
|
||||
ASpawnableActor* Spawn();
|
||||
|
||||
/** Create actor with delegation callback. */
|
||||
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||
|
||||
Reference in New Issue
Block a user