I have an actor component, let’s call it a Character Sheet.
This Character Sheet can have a number of Stats.
There’s the UStatsAndSkills C++ class for the character sheet, and it has a TMap<FName, UStat *> to the UStat C++ class for specific stats.
Relevant declarations include:
UCLASS(Blueprintable, ClassGroup=(StatsAndSkills), BlueprintType, DefaultToInstanced, EditInlineNew, meta = (UsesHierarchy))
class UStat : public UObject
{
UCLASS(Blueprintable, ClassGroup=(StatsAndSkills), meta=(BlueprintSpawnableComponent))
class SCAPES_API UStatsAndSkills : public UActorComponent, public ISymbolValue
{
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Stats and Skills|Configuration")
TMap<FName, UStat*> Stats;
In the editor, when I add this component to an actor, I can add an element to the map using “+”
However, it shows up as “None” and I can’t actually instantiate it. There’s no “New” option on the item, even though the class is marked EditInlineNew.
If I create a subclass of UStat in the regular content browser, I can’t drag it into the empty “None” slot, because of course the blueprint is a class, and the map wants an instance.
I want instances here, because the state objects actually are more like little stateful Excel sheets – they can evaluate formulas, have buffs/debuffs tied to actors or time or other sources, be depleted and replenished, regenerate, and so forth.
I thought that this was exactly what DefaultToInstanced and EditInlineNew was for! But, alas, it doesn’t seem to work.
What am I missing? How am I supposed to structure this? I don’t particularly want to have a parallel map of TSubclassOf<> that points to the stat blueprint classes, and then have to create object instances at runtime. (This presumably also significantly complicates serialization/save/load, because stats themselves can come and go.)