I am attempting to create a usable list of scenecomponents for a user to select one in an array.
I have created a struct, FComponentListItem:
USTRUCT()
struct FComponentListItem
{
GENERATED_USTRUCT_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Component")
USceneComponent* ComponentInQuestion;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Selection")
bool bSelected;
};
And I have created another struct with a TArray of these structs on an ActorComponent called InteractionComp.
In my actors OnConstruction function, I call a function on InteractionComp that finds all usable scenecomponents on the actor and then creates an FComponentListItem struct and copies in the appropriate information. This should then be usable by the user. Unfortunately, I can’t find a way to populate this array in a meaningful way.
void UInteractionComp::OnConstruction(const FTransform& Transform)
{
if (ComponentListMaster.Num() < 1)
{
ComponentListMaster.Empty();
TArray<UActorComponent*> Components = GetOwner()->GetComponents().Array();
for (auto& Component : Components)
{
FComponentListItem Item;
Item.ComponentInQuestion = Cast<USceneComponent>(Component);
Item.bSelected = false;
ComponentListMaster.Add(Item);
}
}
}
Every time this code runs, (ComponentListMaster < 1) returns true, even if the list was populated with 5 members in the previous run.