So I’m trying to develop a way for a user to design a message, which has components attached to it using structures.
Here’s my structure that will contain the entire message:
USTRUCT(BlueprintType)
struct FMessageData
{
GENERATED_USTRUCT_BODY();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Data")
WhatGoesHere Components;
};
The message would contain an array of components, but each component has a different structure defintion. For example:
USTRUCT(BlueprintType)
struct FButtonComponent
{
GENERATED_USTRUCT_BODY();
int Type = 2;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Data")
int Style = 1;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Data")
FString Label;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Data")
FEmoji Emoji = FEmoji();
};
USTRUCT(BlueprintType)
struct FStringSelectComponent: public FMessageComponent
{
GENERATED_USTRUCT_BODY();
int Type = 3;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Data")
FString CustomID;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Data")
TArray<FSelectOptions> Options;
};
Is there a way for me to allow the user to add the different types of structure to the Components array or is there another approach I can take?
I have tried:
- Using a base class and use
TArray<FBaseComponent> Components
so the other components inherit from it. - Using Unions but they cannot be used on a UPROPERTY.
- Using templates but they cannot be used on a USTRUCT.
but none of these work.