mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
Actors that spawn other actors (no meshes yet - that segfaults)
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
#include "SpawnableActor.h"
|
||||||
|
|
||||||
|
#include "UObject/Object.h"
|
||||||
|
|
||||||
|
DEFINE_LOG_CATEGORY(SpawnableActorLog);
|
||||||
|
|
||||||
|
ASpawnableActor::ASpawnableActor()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASpawnableActor::~ASpawnableActor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASpawnableActor::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASpawnableActor::BeginDestroy()
|
||||||
|
{
|
||||||
|
Super::BeginDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASpawnableActor::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ASpawnableActor::SetMesh()
|
||||||
|
{
|
||||||
|
//BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
||||||
|
//BaseMesh->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
|
/*static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));
|
||||||
|
|
||||||
|
if (BaseMeshAsset.Object)
|
||||||
|
{
|
||||||
|
BaseMesh->SetStaticMesh(BaseMeshAsset.Object);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#include "SpawningActor.h"
|
||||||
|
|
||||||
|
#include "SpawnableActor.h"
|
||||||
|
|
||||||
|
#include "Engine/World.h"
|
||||||
|
#include "UObject/Object.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASpawningActor::Spawn()
|
||||||
|
{
|
||||||
|
//SpawnActor<ASpawnableActor>(this, this);
|
||||||
|
|
||||||
|
FTransform location;
|
||||||
|
FRotator rotation;
|
||||||
|
//GetWorld()->SpawnActor<ASpawnableActor>(ASpawnableActor::StaticClass(), &spawnLocation);
|
||||||
|
|
||||||
|
/*ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(
|
||||||
|
ASpawnableActor::StaticClass(),
|
||||||
|
NAME_None,
|
||||||
|
&location,
|
||||||
|
&rotation,
|
||||||
|
nullptr, // ??
|
||||||
|
false, // bNoCollisionFail
|
||||||
|
false, // ??
|
||||||
|
nullptr, // owner
|
||||||
|
nullptr // instigator
|
||||||
|
);*/
|
||||||
|
//ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor<ASpawnableActor>(&spawnLocation);
|
||||||
|
ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass());
|
||||||
|
|
||||||
|
spawnedActor->SetMesh();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Unreal Core
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "UObject/NoExportTypes.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();
|
||||||
|
|
||||||
|
void SetMesh();
|
||||||
|
|
||||||
|
/** Mesh to use */
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", 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;
|
||||||
|
};
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Unreal Core
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "UObject/NoExportTypes.h"
|
||||||
|
|
||||||
|
// EventCenterPlugin
|
||||||
|
#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")
|
||||||
|
void Spawn();
|
||||||
|
|
||||||
|
/** 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;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user