I attempt to create and add components via C++ to an existing actor in editor mode. I have to do this while editing values and therefor i’ve overwritten the PostEditChangeProperty method. Since its not allowed to create components outside of the constructor using the CreateDefaultSubobject function i m using the ConstructObject function which do not crash. The components were added and shown in the Details panel of the actor but the StaticMeshComponent which is created inside my component is not shown.
I tried to create and attach my component inside the constructor of the actor and the StaticMeshComponent is visible (so the component itself is working fine). Are there any limitations in dynamically creating actors / components based on editor events (like PostEditChangeProperty)?
This is the code creating the components:
for (int x = 0; x < Width; x++)
{
for (int z = 0; z < Height; z++)
{
FString Name = TEXT("DebugTile_") + FString::FromInt(x) + TEXT("_") + FString::FromInt(z);
UTileDebug* TileDebug = ConstructObject<UTileDebug>(UTileDebug::StaticClass(), this, FName(*Name));
if (TileDebug)
{
TileDebug->initialize(TileSize - 2.0f * TileDebugPadding, TileDebugPadding);
TileDebug->AttachTo(RootComponent);
TileDebug->SetVisibility(true, true);
TileDebug->SetRelativeLocation(FVector(x * TileSize + TileSize * 0.5f, 0, z * TileSize + TileSize * 0.5f));
TileDebug->RegisterComponent();
}
}
}
This is the code inside the component
TileMesh = CreateDefaultSubobject(TEXT(“TileDebugVisual”));
static ConstructorHelpers::FObjectFinder Box(TEXT("/Engine/BasicShapes/Cube"));
if (Box.Succeeded())
{
TileMesh->SetStaticMesh(Box.Object);
}
TileMesh->AttachTo(this);