mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
Spawn in random location and fall
This commit is contained in:
@@ -12,16 +12,17 @@ ASpawnableActor::ASpawnableActor()
|
|||||||
// You can turn this off to improve performance if you don't need it.
|
// You can turn this off to improve performance if you don't need it.
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
|
||||||
|
// Attach a mesh to the object.
|
||||||
static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));
|
static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));
|
||||||
//static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.uasset'"));
|
|
||||||
//UStaticMesh* Asset = BaseMeshAsset.Object;
|
|
||||||
BaseMesh = BaseMeshAsset.Object;
|
|
||||||
|
|
||||||
|
BaseMesh = BaseMeshAsset.Object;
|
||||||
|
|
||||||
BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
||||||
BaseMeshComponent->SetupAttachment(RootComponent);
|
BaseMeshComponent->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
||||||
|
|
||||||
|
BaseMeshComponent->SetSimulatePhysics(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASpawnableActor::~ASpawnableActor()
|
ASpawnableActor::~ASpawnableActor()
|
||||||
@@ -42,18 +43,3 @@ void ASpawnableActor::Tick(float DeltaTime)
|
|||||||
{
|
{
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ASpawnableActor::SetMesh()
|
|
||||||
{
|
|
||||||
// NB: Everything below segfaults
|
|
||||||
//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);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "Engine/World.h"
|
#include "Engine/World.h"
|
||||||
#include "UObject/Object.h"
|
#include "UObject/Object.h"
|
||||||
|
#include "Math/UnrealMathUtility.h"
|
||||||
|
|
||||||
|
|
||||||
DEFINE_LOG_CATEGORY(SpawningActorLog);
|
DEFINE_LOG_CATEGORY(SpawningActorLog);
|
||||||
|
|
||||||
@@ -37,11 +39,12 @@ void ASpawningActor::Tick(float DeltaTime)
|
|||||||
|
|
||||||
void ASpawningActor::Spawn()
|
void ASpawningActor::Spawn()
|
||||||
{
|
{
|
||||||
//SpawnActor<ASpawnableActor>(this, this);
|
float x = FMath::RandRange(-1000.0f, 1000.0f);
|
||||||
|
float y = FMath::RandRange(-1000.0f, 1000.0f);
|
||||||
|
float z = FMath::RandRange(-1000.0f, 1000.0f);
|
||||||
|
|
||||||
FTransform location;
|
FVector location(x, y, z);
|
||||||
FRotator rotation;
|
FRotator rotation;
|
||||||
//GetWorld()->SpawnActor<ASpawnableActor>(ASpawnableActor::StaticClass(), &spawnLocation);
|
|
||||||
|
|
||||||
/*ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(
|
/*ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(
|
||||||
ASpawnableActor::StaticClass(),
|
ASpawnableActor::StaticClass(),
|
||||||
@@ -54,11 +57,9 @@ void ASpawningActor::Spawn()
|
|||||||
nullptr, // owner
|
nullptr, // owner
|
||||||
nullptr // instigator
|
nullptr // instigator
|
||||||
);*/
|
);*/
|
||||||
//ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor<ASpawnableActor>(&spawnLocation);
|
|
||||||
|
// TODO(bt): This will memory leak.
|
||||||
ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass());
|
ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass());
|
||||||
|
spawnedActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::ResetPhysics);
|
||||||
spawnedActor->SetMesh();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ public:
|
|||||||
ASpawnableActor();
|
ASpawnableActor();
|
||||||
~ASpawnableActor();
|
~ASpawnableActor();
|
||||||
|
|
||||||
void SetMesh();
|
|
||||||
|
|
||||||
/** Mesh to use */
|
/** Mesh to use */
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true"))
|
||||||
class UStaticMeshComponent* BaseMeshComponent;
|
class UStaticMeshComponent* BaseMeshComponent;
|
||||||
|
|||||||
Reference in New Issue
Block a user