diff --git a/Source/EventCenterPlugin/Private/SpawnableActor.cpp b/Source/EventCenterPlugin/Private/SpawnableActor.cpp index 8f131b2..4f8a582 100644 --- a/Source/EventCenterPlugin/Private/SpawnableActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawnableActor.cpp @@ -12,16 +12,17 @@ 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 BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'")); - //static ConstructorHelpers::FObjectFinder BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.uasset'")); - //UStaticMesh* Asset = BaseMeshAsset.Object; - BaseMesh = BaseMeshAsset.Object; + BaseMesh = BaseMeshAsset.Object; BaseMeshComponent = CreateDefaultSubobject(TEXT("BaseMesh")); BaseMeshComponent->SetupAttachment(RootComponent); BaseMeshComponent->SetStaticMesh(BaseMesh); + + BaseMeshComponent->SetSimulatePhysics(true); } ASpawnableActor::~ASpawnableActor() @@ -42,18 +43,3 @@ void ASpawnableActor::Tick(float DeltaTime) { Super::Tick(DeltaTime); } - - -void ASpawnableActor::SetMesh() -{ - // NB: Everything below segfaults - //BaseMesh = CreateDefaultSubobject(TEXT("BaseMesh")); - //BaseMesh->SetupAttachment(RootComponent); - - /* - static ConstructorHelpers::FObjectFinder BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'")); - if (BaseMeshAsset.Object) - { - BaseMesh->SetStaticMesh(BaseMeshAsset.Object); - }*/ -} diff --git a/Source/EventCenterPlugin/Private/SpawningActor.cpp b/Source/EventCenterPlugin/Private/SpawningActor.cpp index f0f5a96..6dc69bc 100644 --- a/Source/EventCenterPlugin/Private/SpawningActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawningActor.cpp @@ -4,6 +4,8 @@ #include "Engine/World.h" #include "UObject/Object.h" +#include "Math/UnrealMathUtility.h" + DEFINE_LOG_CATEGORY(SpawningActorLog); @@ -37,11 +39,12 @@ void ASpawningActor::Tick(float DeltaTime) void ASpawningActor::Spawn() { - //SpawnActor(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; - //GetWorld()->SpawnActor(ASpawnableActor::StaticClass(), &spawnLocation); /*ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor( ASpawnableActor::StaticClass(), @@ -54,11 +57,9 @@ void ASpawningActor::Spawn() nullptr, // owner nullptr // instigator );*/ - //ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(&spawnLocation); + + // TODO(bt): This will memory leak. ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass()); - - spawnedActor->SetMesh(); - - + spawnedActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::ResetPhysics); } diff --git a/Source/EventCenterPlugin/Public/SpawnableActor.h b/Source/EventCenterPlugin/Public/SpawnableActor.h index 0fa5b4e..9b46f01 100644 --- a/Source/EventCenterPlugin/Public/SpawnableActor.h +++ b/Source/EventCenterPlugin/Public/SpawnableActor.h @@ -20,8 +20,6 @@ public: ASpawnableActor(); ~ASpawnableActor(); - void SetMesh(); - /** Mesh to use */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true")) class UStaticMeshComponent* BaseMeshComponent;