What am I missing about EditInlineNew for UObjects?

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.

unreal-stats-not-new-able.png

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.

unreal-not-draggable.png

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.)

2 Likes

On TArray’s at least, you need to specify the “Instanced” keyword on the UPROPERTY:



UPROPERTY(Instanced)
TArray<USomeObject*> Objects;


I’m unsure if it works equally on TMaps, but that’s probably at least part of the issue.

Interesting! I had misread the documentation that said “Object (UCLASS) properties only.”


 UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Stats and Skills|Configuration", Instanced)
TMap<FName, UStat*> Stats;


This allows me to select a “Stat” from the drop-down menu, but doing so then crashes with a stack overflow inside GenerateChildrenForProperty.
Maybe I have some over-aggressive annotation somewhere.
Thanks for the hint, I’ll keep looking!

Separately, if I wanted to create “Stats” as separate assets, and add them to this map (or maybe an array,) and then keep the instance of each carried forward through serialization, savegame, etc, how would I do that?
Is there any way to do that without a separate TSubclassOf<> array and an inner dictionary that gets populated from the array?

To do that you’d need to create a factory so that you can create an object of that class directly in the content browser (similar to how Data Assets are created) - but otherwise you would have to go down the TSubclassOf<> route.

Thanks for the additional note. I’m going to read up on the UFactory and FAssetAction API and see if I can make that work!

Also, it seems “CallInEditor” doesn’t actually make a button show up in the editor rollouts for a C++ event/function, the way they do for blueprint.
Is there some straightforward way to make that happen, too?

I had a similar issue, always saw engine crashes.

This is how I solved it.

0x00007FFEB5276DD0 (UnrealEditor-Core.dll) (UnrealEditor.exe 中)处有未经处理的异常: 0xC00000FD: Stack overflow (参数: 0x0000000000000001, 0x000000874AE03FD8)。

It seems your setup make Details View layout system stocked in infinite recursion. Generally, array itself should not use the same category with its element.

1 Like