I have a Smart Object that is completely working in a class I can drop the actor in the scene and it works fine.
Now I have a secondary class that needs to make a array of these objects in the scene. Ive tried the following with them all failing in a engine crash:
TArray<ABuildingModTile*> Column;
FActorSpawnParameters SpawnInfo;
ABuildingModTile* someItem = GetWorld()->SpawnActor<ABuildingModTile>(GetClass(), SpawnInfo);
Column.Add(someItem);
Column.Add(ObjectInitializer.CreateDefaultSubobject < ABuildingModTile >(this, TEXT("BuildingModTile")));
I’m not understanding something,
Adding more information:
This is the base Class I am trying to create a array from:
#pragma once
#include "GameFramework/Actor.h"
#include "BuildingMod_Defines.h"
#include "BuildingModTile.generated.h"
/**
*
*/
UCLASS(Blueprintable, BlueprintType)
class RPGSYSTEM_DEMO_API ABuildingModTile : public AActor
{
GENERATED_BODY()
UPROPERTY()
TSubobjectPtr<USphereComponent> BaseRoot;
void OnConstruction (const FTransform & Transform) override;
//Marks the Size of the modular set
//X Width Y Depth Z Height
FVector TileSize;
//Movement Triggers
bool RightShift;
bool LeftShift;
bool ForwardShift;
bool BackShift;
bool WaitForRelease;
FVector CenterPOS;
bool init_meshes;
void BuildFloorAndWall(const FTransform & Transform);
public:
ABuildingModTile(const FObjectInitializer& ObjectInitializer);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Setup")
TArray<UStaticMesh*> PartType_Meshes;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Enum)
TEnumAsByte<BuildPart_Types::BuildPart_Type> FloorIndex;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Enum)
TEnumAsByte<BuildPart_Types::BuildPart_Type> WallType;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Setup", Meta = (MakeEditWidget = true))
FTransform CenteredControlWidget;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Enum)
TEnumAsByte<BuildPart_POSTypes::BuildPart_POSType> WallPOS;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Setup")
TArray<FWallPOSType> WallRotPOSData;
UPROPERTY()
UInstancedStaticMeshComponent * Floor;
UPROPERTY()
UInstancedStaticMeshComponent * Wall;
void UpdateWallMesh(bool IsUp);
void UpdateWallPOS(bool IsPositive);
};
This is the new Class:
#include "GameFramework/Actor.h"
#include "BuildingModTile.h"
#include "BuildingModGen.generated.h"
/**
*
*/
UCLASS(Blueprintable, BlueprintType)
class RPGSYSTEM_DEMO_API ABuildingModGen : public AActor
{
GENERATED_BODY()
ABuildingModGen(const FObjectInitializer& ObjectInitializer);
UPROPERTY()
TSubobjectPtr<USphereComponent> BaseRoot;
public:
//UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Tiles")
TArray<ABuildingModTile*> Column;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "RPGSystem_Demo.h"
#include "BuildingModGen.h"
ABuildingModGen::ABuildingModGen(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
BaseRoot = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));
RootComponent = BaseRoot;
FActorSpawnParameters SpawnInfo;
ABuildingModTile* someItem = GetWorld()->SpawnActor<ABuildingModTile>(GetClass(), SpawnInfo);
Column.Add(someItem);
//Column[0]->AttachRootComponentToActor(this);
}
This on crashes on Spawn actor
The other version crashes at:
Column.Add(ObjectInitializer.CreateDefaultSubobject < ABuildingModTile >(this, TEXT(“BuildingModTile”)));