I’ve got a blueprint function that runs whenever I press a button in-game.
The function modifies a tilemap’s data
PROBLEM: the changes are not applied till AFTER I stop and restart the application.
Code of blueprint function:
UE_LOG(LogTemp, Warning, TEXT("BeginGenerateWorld"));
TObjectIterator<AActor> Itr;
UWorld* TheWorld = Itr->();
UPaperTileSet * ts = LoadObjFromPath<UPaperTileSet>(TEXT("/Game/TilemapProject/Tile/oryx_world_bg0.oryx_world_bg0"));
// That's how I get the tilemap actor
auto actorItr = TActorIterator<APaperTileMapActor>(TheWorld);
APaperTileMapActor * tmactor = *actorItr;
auto tm = tmactor->GetRenderComponent()->TileMap;
auto tmlayer = tm->TileLayers[0];
for (int i = 0; i < tmlayer->LayerHeight; ++i)
for (int j = 0; j < tmlayer->LayerWidth; ++j)
{
FPaperTileInfo pti;
pti.TileSet = ts;
pti.PackedTileIndex = FMath::RandRange(0, pti.TileSet->GetTileCount() - 1);
tmlayer->SetCell(j, i, pti);
}
UE_LOG(LogTemp, Warning, TEXT("EndGenerateWorld"));