Download

Is "Outer" same as parent

This is one of the NewObject overloads:

template< class T >
T* NewObject
(
UObject* Outer=(UObject*)GetTransientPackage(),
UClass* Class=T::StaticClass()
)

What I m a bit unclear on is whether Outer is the same as parent ? If i have two classes, A and B, and A is a container of multiple Bs, and Bs needs access to A as a parent, can I just use this Outer here to pass A as parent. Such as :

void A::CreateChild
{
B* child = NewObject<B>(this);
_children.Add(child); // _children would be a TArray or TMap
}

Is this the right use of Outer ? Any gotchas I should be aware of ?

Also - what is this GetTransientPackage() that the function defaults to ?

The outer would be the container where the object is spawned, so it might or might not be the parent you are seeking :D. GetTransientPackage() will return the current place or environment where the object is spawned, think about it like a run-time scene container (correct me if I’m wrong please :D).

When I need to hold an hierarchy with a parent <-> children relationship I normally do it ad-hoc and not using the outer, in the end it’s more flexible but you are OK to use the outer if you wish.