Murtaza Raza
Murtaza Raza

Reputation: 67

Owner in Unreal Engine

So I recently switched from Unity to Unreal and I cant understand the concept of Owner in Unreal. I understand parent-child relationships but what exactly is an owner? Changing the owner of an actor does not change it's hierarchy so how exactly is unreal handling ownerships?

Thank you in advance.

EDIT: Removed rendering related detail that I found is not a good use case for ownership.

Upvotes: 6

Views: 2891

Answers (1)

goose_lake
goose_lake

Reputation: 1480

There are several types of "parent-child" relationships that are frequently used in Unreal in context of UObjects, and which don't necessarily have to be the same (i.e. the same object can have three different "parents" in the different realtionships).

One is transform attachment (only relevant for actors), where an actor which is "attached" to another actor (its "attach parent") inherits transforms before applying its own.

Another one is object-lifetime parent-child relationships, where each object has an "outer", and if an object's outer is removed (garbage collected etc.), so is the object. For AActors, by default that's the ULevel they are in, so it's not so important.

The third one (again only relevant for actors) is the ownership relationship, which have some interesting properties. For one, if an actor's owner gets Destroy-ed, so does the actor. For example:

// Make an owner actor
AActor* Parent = GetWorld()->SpawnActor<AActor>();

// Make an owned actor
FActorSpawnParameters SpawnParameters;
SpawnParameters.Owner = Parent; 
AActor* Child = GetWorld()->SpawnActor<AActor>(AActor::Static_Class(), FTransform(), SpawnParameters);

// Destroy the owner
Parent->Destroy();
// After this, the Child actor is also destroyed

Another property of this relationship has to do with replication. Properties such as bOnlyRelevantToOwner, as well as conditional property replication such as COND_OwnerOnly, COND_SkipOwner rely on this. Property replication is a very big topic that won't fit in the scope of one answer, but the linked page of UE documentation can help.

All in all, it's important to note: actors don't necessarily have to have an owner, and unless you need the owner to be set for a specific reason such as the aforementioned functionalities, it's standard practice not to set one.

Upvotes: 8

Related Questions