I wish to create many such struct variables in a blueprint class and set their values in Class Defaults, like health, mana, stamina, armour etc.
I wish to have a variable in C++ such as:
TMap<MyEnum, Fattribute_data*>
such that, when I create the struct variable(s) in Blueprints and pass them to a blueprint callable method, I wish to have those structs mapped inside that TMap.
But, what is happening is, when I create some Fattribute_data variables such as health, mana, stamina in blueprints and set their values, the function creates the TMap, but upon accessing any value of the TMap using any key, I get only the last struct’s values.
I do not get the values of other structs.
Please help me.
How to write a function that can create such a map where any blueprint struct can simply have it’s address mapped by a TMap variable such as that?
A couple of things here, if you want Blueprint to have access to the data you need to declare the members as UPROPERTIES. And, you’ll need a GENERATED_BODY() in the structure definition. So, like:
And then… USTRUCTs, unlike UObjects, are not garbage collected. You probably want the map to contain their value. Otherwise, you’d have to manage their memory yourself with smart pointers etc or whatever. So, your TMap will just have the struct value and not a pointer.
You just make a TMap UPROPERTY, as above, without making it a pointer.
Then the TMap is allocated as part of the component, which is a garbage collected UObject.
And then, the TMap itself manages allocating and de-allocating your structures. It’ll allocate a new Fattribute_data when needed, and delete it when it’s not needed.
TMap, TArray, their jobs are to make developing easier sooo I always just let them do that.