When performing a Hot Reload in my Unreal project, an AActor class loses it’s internal state due to a duplicate Guid.
My class has the following member:
UPROPERTY()
UPaperTileMapComponent* TileMap;
In the constructor I do the following:
TileMap = CreateDefaultSubobject<UPaperTileMapComponent>("terrain");
RootComponent = TileMap;
When I drag the AActor into the scene, the tilemap is rendered correctly and everything works. But as soon as I perform a Hot Reload, the TileMap can not be rendered anymore (duplicate name “terrain”). The component isn’t rendered until I manually change the name and compile again.
Changing the code to the following works though:
char name[256];
sprintf(name, "tilemap_%d", static_cast<int>(FMath::RandRange(0, 10000)));
TileMap = CreateDefaultSubobject<UPaperTileMapComponent>(name);
RootComponent = TileMap;
This ensures that the name is always different to the previous hot-reload name. The map is correctly rendered after each hot reload.
I think this might be a bug in the Garbage Collection? There is no other Actor that holds a reference to this component.