What is meant by "Outer Object"?

I am looking at the documentation for creating UObject instances here:

It mentions that each method takes an optional “Outer Object” but I have no idea what that is or what it means.

Right now I am trying this, but while it compiles, it gives me an error: NewObject with empty name can’t be used to create default subobjects (inside of UObject derived class constructor) as it produces inconsistent object names. Use ObjectInitializer.CreateDefaultSuobject<> instead.

UHexTile* newTile = NewObject<UHexTile>(this);

Now I sort of understand what the error is saying, well not really but sort of, but despite the presumed typo in the suggested function, I don’t see how I could use it since I am not doing this in the ctor. Plus I don’t understand the “empty name” bit since the documentation specifically states using NewObject is designed to generate the name for you.

You should use ‘NewObject’ outside of the constructor.

In constructor, you would use:

UHexTile* newTile = CreateDefaultSubobject<UHexTile>(TEXT("HexTileName"));

This way, “Outer” (or owner) of newTile is the object that is currently constructed.

Hope this helps…

But this isn’t being called in the constructor. Err, well maybe it is from a long chain of things. I need to check I guess. But it can just as easily be called at any time.

If this is called outside of constructor, try this:

static int32 TileCounter = 0;
FString TileName = FString::Printf(TEXT("HexTile_%d"), TileCounter++);
UHexTile* NewTile = NewObject<UHexTile>(this, UHexTile::StaticClass(), *TileName);

This should give all tiles unique name…

Long story short, Outer object is something used in unreal code reflection, which looks more or less like this:


Construct Object From Class

What does outer object mean for this blueprint node?

It’s asking for outer object which specifies lifetime.

The “Outer” input will serve as the new object’s owner, which controls the lifetime of the created

I want to know what outer object is so I can figure out what the lifetime is.