Can you storing components added to actor at runtime in aTArray?

RyanNielson
Sat, 16 May 2020 19:18:38 +0000
Community & Industry Discussion

Is there something special you have to do to get components added to an actor at runtime to show up in the editor details pane components list? I have a UChunkComponent that inherits from UProceduralMeshComponent. Right now it only has a tick function which seems to be getting called but I don’t see the four components added to the actor like I’d expect in the details pane. RootComponent below is just a USceneComponent I added in the constructor.

The code below is a snippet of what I have so far. I’m suspecting it’s not showing up because I’m adding the newly create scene components to a TMap, but I’m not sure why. Ideally I want to store them in this map so that I can do lookups based on a grid location. I’ve also tried storing them in a TArray and I’m running into similar issues. Any insight into why this is happening, or the correct way to go about doing something like this, would be greatly appreciated. The number of ChunkComponents to be generated at runtime is configurable so I can’t just store them all as their own properties.

void AWorldGenerator::BeginPlay()
{
    Super::BeginPlay();

    for (int32 x = 0; x < 2; x++)
    {
        for (int32 y = 0; y < 2; y++)
        {
            FString Name = FString::Printf(TEXT("Chunk-%i-%i"), x, y);

            UChunkComponent* Chunk = NewObject<UChunkComponent>(this, FName(Name));
            Chunk->AttachToComponent(RootComponent,  FAttachmentTransformRules::KeepRelativeTransform);
            Chunk->RegisterComponent();
            Chunks.Add(FIntVector(x, y, 0), Chunk);
        }
    }
}

// In header
UPROPERTY(VisibleInstanceOnly)
TMap<FIntVector, UChunkComponent*> Chunks;

1 post - 1 participant