Unreal Engine Actors
Basic game-play elements, Actors and objects;
Actor : Placed into a level. Actors are a generic class that support 3D transformations (Translation, Rotation, Scale). Actors can created (Spawned) and destroyed using C++ code or Blueprint; AActor is the Base class of All Actors;
Actors types like : StaticMeshActor, CameraActor etc;
Actors not store Transform data; The data of Transform is the Root Component, if exists is used instead.
Creating Actors
New Instances of AActor classes = Called Spawning;
Done By Using Function Name = SpawnActor(); // see more click on it;
// Spawan Actor
FTransform SpawanLocation;
AES_SpawanEnemy* SpawanActor = GetWorld()->SpawnActor
(AES_SpawanEnemy::StaticClass(), SpawanLocation);
UClass* ActorClass = SpawanActor->GetClass();
Components :
Actors containers that hold special types of objects called Components. Components uses to control to actors behavior or how they rendered etc. The other main function of Actors is the Replication of properties and function calls across the network during play.
Components = Associated with their containing Actors when they are created;
Types Of Components
UActorComponent :
- Base Component
- Include as part of an Actor
- It Can Tick if you want it to
- It associated with specific Actors, but do not placed specific place in the world;
- Used :: Conceptual Functionality like AI or interpreting player input.
USceneComponent :
- It have transforms.
- Transform is a position of world, defined by location, Rotation and scale.
- It attached to each other with hierarchical fashion.
- Used :: Actors Location, Rotation and scale are taken by UScenComponent and Root of hierarchy.
UPrimitiveComponent :
- PrimitiveComponent are ScenComponent that have a Graphical representation of some kind (mesh or Particle Systems ).
- Physics and collision settings are here;
Actor support Hierachy of ScenComponents. Each Actor have Root Component property that acts as the root for the Actor. Actors don't have any types of Transforms or any kind of Locations that have with SceneComponent with RootComponent property.
TargetScene = CreateDefaultSubobject<USceneComponent>(TEXT("Target Point"));
RootComponent = TargetScene;
FTransform SpawnLocation;
FVector TargetLoc = GetActorLocation();
FRotator TargetRot = GetActorRotation();
GetWorld()->SpawnActor<AES_SpawanEnemy>(AES_SpawanEnemy::StaticClass(), TargetLoc, TargetRot);
In C++
PlayerCover = CreateDefaultSubobject<UStaticMeshComponent>("Player Static Mesh");
RootComponent = PlayerCover;
PlayerCover->SetRelativeLocation(FVector(0.0f, 0.0f, 10.0f));
static ConstructorHelpers::FObjectFinder<UStaticMesh>
CylinerAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'")); // Helps to Object find;
if (CylinerAsset.Succeeded()) {
PlayerCover->SetStaticMesh(CylinerAsset.Object);
PlayerCover->SetWorldScale3D(FVector(0.8f));
//PlayerCover->SetCollisionProfileName("Pawn");
// PlayerCover->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
PlayerCover->SetSimulatePhysics(true);
// IMyFirstInterface::SetCollisionProfileName(SpawanEnemyActor);
}
// Spring Arm Attach Camera With it!!;
SpringArm = CreateDefaultSubobject<USpringArmComponent>("Spring Arm");
SpringArm->SetupAttachment(RootComponent);
SpringArm->SetRelativeRotation(FRotator(0.f, -24.9999943f, 0.f));
SpringArm->SetRelativeLocation(FVector(0.000000f, 0.000000f, 70.000000f));
SpringArm->TargetArmLength = 2469.0195312f;
SpringArm->ProbeSize = 29.848629f;
SpringArm->bEnableCameraLag = true;
SpringArm->CameraLagSpeed = 3.0f;
// Attach Camera With Spring Arm;
Camera = CreateDefaultSubobject<UCameraComponent>("Actual Camera");
Camera->SetFieldOfView (36.5714378f);
Camera->SetupAttachment(SpringArm, USpringArmComponent::SocketName);
Ticking
How actors updated in Unreal Engine; All Actors have ability to Tick every frame or each frame; user defined interval, allowing to you perform any update calculations or actions that can be perform;
Actors by Default tick in Tick() function;
ActrosComponents Ability :: Updated by default use the TickComponent() function
Actor Life Cycle https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Actors/ActorLifecycle/index.html
Replication :
Use :: Actors within the world in sync when dealing with Network multiplayer games. Property and Functions calls can both be Replicated. Complete control over the stat of the game on all clients;
Destroying Actors
Actors not Garbage Collected, as the world Object holds a list of Actors references.
Destroying Actor :: Destroy(); // This function removes from the level and mark them pending Kill
Pending Kill :: They will hang around until they are cleaned up on the next garbage Collection ;
Comments
Post a Comment