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.
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.
After some testing, it seems Outer has to do with the garbage collection of the object as well. It seems like even if there are strong references to a UObject via TSharedPtr or UPROPERTY, if the Owner goes away, so do all the objects that were created with NewObject<…>(Owner).
I ran into this because I have a UMenuContext object stored on my UMyGameInstance class. The UMenuContext has a stack of UMenuWindow’s. These were getting deleted when I switched maps and the reason was that they were parented to the current AMenuPlayerController instead of the UGameInstance and so the garbage collector was deleting them when the player controller switched to a new one.
yes. in blueprint usually use GetOuterObject to find the UMG instance from any widget in that BP. Using GetParent will return direct parent of the widget in the hierarchy. So basically the outerobject is parallel to parenting, just gives another way for you to find references in like “containing” relation. easier to understand