I’m trying to dynamicly spawn tilemaps as my levels are generated procedurally. Each tilemap is a room, made in the editor, and could be spawned multiple times.
My approach right now is to create a single actor, and adding Tile map components for each room.
This works fine if the generation is done within the constructor, however I need it to be dynamic, so following https://answers.unrealengine.com/questions/199144/add-components-dynamically.html I tried the following code :
void AMapGenerator::BeginPlay()
{
Super::BeginPlay();
UPaperTileMapComponent* createdComp = NewObject<UPaperTileMapComponent>();
if (createdComp)
{
createdComp->RegisterComponent();
createdComp->AttachTo(GetRootComponent(), NAME_None);
}
}
The new component isn’t registered upon creation, but RegisterComponent() will give a crash :
Ensure condition failed: MyOwner && MyOwner->GetWorld()
I also thought of using a single huge tilemap and copy parts of my rooms, but I’m not sure that it would be efficient.
What would be the best approach in this case ?