Download

Holding multiple data types, is Struct the best option?

Greetings,

I want to hold an array of multiple data values of different types, so thinking back to my UDK days I figured just make a struct and then an array of that struct but now im not so sure.

My objective is to allow the user working with blueprints to set transition data for some objects something like:

struct TransitionData
{
float Opacity;
vector2D location;
float rotation;
float scale;
FColor DrawColor;
float TransitionRate;
bool bSnap;
}

and then have something like:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, category = “Transitions”)
TArray<TransitionData> Transitions;

but declaring the struct and the array kill my class declaration, is something like this even possible?



//USTRUCT(BlueprintType)
struct STransitionData
{
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu TransitionData")
	float OpacityB;
};

UCLASS()
class MENUBASE_API UMenuComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UMenuComponent();

	//UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Drawing")
	STransitionData OpeningTransition;
};


that bit compiles but It wont show on bp, any ideas?

What does “kill” mean? Do you get compile errors? If so, what errors?

I believe you need GENERATED_BODY() in the struct body as well.

Ryian is right, you’re missing the “GENERATED_USTRUCT_BODY()” in your struct-definition.


USTRUCT(BlueprintType)
struct FTransitionData
{
  GENERATED_BODY()

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu TransitionData")
  float OpacityB;
};

Note the ‘F’ prefix on the struct name. This is required for all USTRUCTs by Unreal’s reflection system (or anyway was until recently and I don’t think has changed).

thanks kamrann, the F thing did the trick, now I can have somewhat of a trail of data to transition my menu items around :smiley:

now the final question is, how can I declare the defaults, I managed to get this to compile:

FTransitionData() 
	: Scale(1)
	, Color(FColor::White)
	, Opacity(1)
	,Time(1)
{}

but that apparently only happens when the item is added to the array of “reset” with the yellow arrow, but all the internal values have their own yellow arrows that reset them to the type’s default.

Is there a way to “Construct” the struct with default values?

and jwatte:

Basically the compiler told me my class declaration was ilegal or something and then all the functions on the cpp had a left of -> need a valid reference pointer complain, as if the class was never declared I guess.

Not a c++ guy, had an intro class and we never touched object oriented, just spaguetti threaded sequential code so sorry if I sound like a total iriet :smiley:


USTRUCT(BlueprintType)
struct FTransitionData
{
  GENERATED_BODY()

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu TransitionData")
  float OpacityB = 2814.4f;
};

This is how it works for me with setting default variables, if I remember correctly.

lol has the same effect, guess it could just be either a bug or something not supported yet, either way thanks for the info, looks a lot cleaner than what I had before :smiley:

k did some more digging and I think I found a much better way to deal with what I am trying to do.

CURVES :smiley:

Digging into the class right now but if what I suspect is true, I dont have to hold an array, I can literally let the user define the values on a curve and just retrieve the values based on the elapsed time. Making blends and loops much easier to deal with and hopefully less stress on the process. It also makes cloning behaviors a lot easier.

Curves are awesome for the use cases where they work!
I use them for things like “size of growing things based on time since spawn” and “tint color based on amount of damage.”

yep thats sorta the idea, that way you can have bezier transitions without having to reinvent the wheel :smiley:

love how they have a getValue(time) function for them, makes life so much easier