Actor
Introduction Actor is one of the most important aspects of Unreal Engine, it lays at the core of everything you will do interacting in the Unreal Editor viewport and the Game World. This core Unrea...
Introduction
Actor is one of the most important aspects of Unreal Engine, it lays at the core of everything you will do interacting in the Unreal Editor viewport and the Game World. This core Unreal Engine Class AActor
forms the basis for any Object you can see in the viewport in the 3d space, this does not include UMG widgets which are overlays.
Components
Actors are made up of various Components.
Info
There are a class of Actors which have very minimal presence in the game world, they are largely managers and extend from the Info
Actor. See Game Framework explained for more.
Spawn
Spawning refers to the process of creating an Actor, similar to New Object though having a physical presence in the game world means Actors are treated differently, because they have components like collision. If an Actors Spawn location is being blocked we call that Encroachment, its when two Actors (or more) share the same physical space.
GetWorld()->SpawnActor();
Since there is a requirement to having a game world we must first GetWorld
to call Spawn on, this function is inherited by all Actors. This is the most basic implementation calling the default constructor.
FActorSpawnParameters SpawnInfo;
SpawnInfo.Owner = this;
SpawnInfo.Instigator = GetInstigator();
SpawnInfo.ObjectFlags |= RF_Transient;
YourActorReference = GetWorld()->SpawnActor(SpawnInfo);
Spawning has the associated structure FActorSpawnParameters
which is used to pass in a number of parameters to the Spawn function as in this example.
GetWorld()->SpawnActor(YourActorClass, SpawnInfo);
The above lets you specify a class with YourActorClass
you may wish this to be editable on children of this class.
Spawning and Destroying Actors in Blueprint
Owner
GetOwner()
Destroy
If you are finished with an Actor simply call the Destroy
method.
YourActor->Destroy();
can bind delegates to spawn/destroy events
Archetypes
This structure FActorSpawnParameters
gives us an opportunity to use another existing Actor as a Template for spawning, as shown below with YourTemplateActor
reference being set to use when Spawned.
FActorSpawnParameters SpawnInfo;
SpawnInfo.Owner = this;
SpawnInfo.Template = YourTemplateActor;
YourActorReference = GetWorld()->SpawnActor(SpawnInfo);
Attachment
Attaching Actors typically happens through their Components, the most basic form of attachment would be through two Actors Root Components using AttachToActor
. \AttachToActor(ParentActor, FAttachmentTransformRules, SocketName);
\if(YourActor->IsAttachedTo(ParentActor)){}
\TArray \ YourOutActors, YourActor->GetAttachedActors(&YourOutActors, false);
YourOutActors
array is now filled with a list of all Actors attached to YourActor
.
\YourActor->DetachFromActor(FDetachmentTransformRules);
Detaches the RootComponent of this Actor from any SceneComponent it is currently attached to.
\FName GetAttachParentSocketName()
Editor
\