RealDocs

AActor::SetOwner

function Engine Blueprint Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: virtualENGINE_APIUFUNCTIONBlueprintCallable

Description

Sets the owner of this actor, which primarily affects network relevancy and RPC routing. An actor is net-relevant to all connections that its owner is relevant to, and client RPCs travel up the owner chain to find the PlayerController.

Caveats & Gotchas

  • Setting the owner affects net relevancy immediately — if NewOwner is not relevant to a connection, this actor also becomes non-relevant, which can cause it to be destroyed on clients that lose relevancy.
  • The owner chain is used for RPC routing: a client RPC on an actor with no owning PlayerController in the chain will be silently dropped by the server. Always ensure the ownership chain leads to a PlayerController for client RPCs to work.
  • Circular ownership chains (A owns B, B owns A) are not detected and will cause infinite loops in code that traverses the owner chain.

Signature

ENGINE_API virtual void SetOwner( AActor* NewOwner );

Parameters

Name Type Description Default
NewOwner AActor* The actor to set as the new owner. Pass nullptr to clear ownership.

Return Type

void

Example

Assigning ownership to route RPCs through a PlayerController C++
// Server-side: ensure a spawned actor's RPCs route to the correct player
void AMyGameMode::SpawnActorForPlayer(APlayerController* PC)
{
	FActorSpawnParameters Params;
	AMyActor* Actor = GetWorld()->SpawnActor<AMyActor>(AMyActor::StaticClass(), Params);
	if (Actor)
	{
		Actor->SetOwner(PC); // RPCs from this actor now route through PC
	}
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.