0% found this document useful (0 votes)
1 views

UE4 Notes

The document provides a comprehensive overview of Unreal Engine programming concepts, including trigger volumes, player interactions, game modes, and physics handling. It covers various coding techniques, such as ray casting, input binding, and animation blending, alongside practical examples for implementing these features in C++. Additionally, it discusses AI behavior, blackboard systems, and game termination procedures, making it a valuable resource for developers working with Unreal Engine.

Uploaded by

Vinc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

UE4 Notes

The document provides a comprehensive overview of Unreal Engine programming concepts, including trigger volumes, player interactions, game modes, and physics handling. It covers various coding techniques, such as ray casting, input binding, and animation blending, alongside practical examples for implementing these features in C++. Additionally, it discusses AI behavior, blackboard systems, and game termination procedures, making it a valuable resource for developers working with Unreal Engine.

Uploaded by

Vinc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

TRIGGER VOLUME

#include “Engine/TriggerVolume.h”
class ATriggerVolume* Name;

● Volume that can detect things entering / leaving.


● APawn inherits from AActor class
● Object of ATriggerVolume* should be assigned to a certain actor. Otherwise, UE will
crash.

UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate; // to have a trigger action on actors
UPROPERTY(EditAnywhere)
AActor* ActorThatOpen;

DELTA TIME

● Used how to get the elapsed time between frames.

UPROPERTY(EditAnywhere)

● Can expose parameters to the Editor anywhere.

110. PLAYER INTERACTION

DefaultPawn - body, PlayerController - mind

PlayerController class has GetPawn()

#include "Engine/World.h"
#include "GameFramework/PlayerController.h"

AActor* ActorThatOpen; // creating an actor in .h


ActorThatOpen = GetWorld()->GetFirstPlayerController()->GetPawn();

114. GAME MODE AND GAME STATE

## To be able to use own specific pawn -- Edit - Project Setting - Default GameMode

https://docs.unrealengine.com/en-US/InteractiveExperiences/Framework/GameMode/index.html
115. MODIFYING DEFAULT PAWN ACTOR & BLUEPRINT

## Blueprint class inherits an “is a” relation.

Adding a Grabber to the pawn -- Grabber can pick up things …


Clone Default Pawn - Create a “Grabber” C++ class - add Grabber to ClonePawn from
component -

117. GETTING PLAYER VIEWPOINT & Location/Rotation

#include “GameFramework/PlayeController.h”
APlayerController::GetPlayerViewPoint

// Get the player viewpoint


GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint();

void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType,


FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

// Get the player viewpoint


FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
OUT PlayerViewPointLocation,
OUT PlayerViewPointRotation
);

UE_LOG(LogTemp, Warning, TEXT("Location: %s, Rotation: %s"),


*PlayerViewPointLocation.ToString(),
*PlayerViewPointRotation.ToString()
);

// Ray-cast out to a certain distance (reach)


// See what it hits

118. USING DrawDebugLine() // DrawDebugXX()

#include “DrawDebugHelpers.h”

Calculating LineTraceEnd

// Draw a line from player showing the reach


FVector LineTraceEnd = PlayerViewPointLocation + FVector(0.f, 0.f, 100.f);
// measured in cm (x,y,z for testing purpose)

Self approach..
FVector LineTraceDirection = PlayerViewPointRotation.Vector();
//Convert a rotation into a unit vector facing in its direction.
FVector b = LineTraceDirection * Reach;
FVector LineTraceEnd = PlayerViewPointLocation + b; // measured in cm

Guided approach…
FVector LineTraceEnd = PlayerViewPointLocation +
PlayerViewPointRotation.Vector() * Reach;

DrawDebugLine
(
GetWorld(),
PlayerViewPointLocation,
LineTraceEnd,
FColor(0, 255, 0),
false,
0.f,
0U,
5.f
);

119. RAY CASTING & PHYSICS & COLLISION

>> Lit - Player Collision to view Mobility

Object -> Collision presets - Object Type - PhysicsBody is the one we can pick up

Quiz
A reusable component accesses the transform (position, rotation, scale) of the object it is
attached to = GetOwner()->GetTransform().

FRotator data type stores rotation.


The Game Mode specifies the Default Pawn that spawns at run time, and we want to modify this
pawn to have a grabber.

120. LineTraceSingleByObjectType()
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
(To access the object’s physics body)
#include “CollisionQueryParams.h”

FCollisionQueryParams
(
FName(TEXT()), // are we using tag? No.. we will use physics channel
Bool bInTraceComplex, // visibility collision using?
Const AActor * InIgnoreActor // which actor to ignore? Yes,self. GetOwner()
)

FHitResult Hit;
// Ray-cast ( Line Trace ) out to a certain distance (reach)
FCollisionQueryParams TraceParam(FName(TEXT("")), false, GetOwner());
// (blank cuz we aren't using, false, ignore us)
GetWorld()->LineTraceSingleByObjectType
(
OUT Hit,
PlayerViewPointLocation,
LineTraceEnd,
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
// To access object from enum, use ::
TraceParam
);

121. Using FindComponentByClass()

Use it to find attached components. <> for generics. Nullptr to initialize pointers.

Add component in blueprint -- PhysicsHandle

#include "PhysicsEngine/PhysicsHandleComponent.h"
private:
float Reach = 150.f;
UPhysicsHandleComponent* PhysicsHandle = nullptr;
In BeginPlay() --
PhysicsHandle = GetOwner()-
>FindComponentByClass<UPhysicsHandleComponent>();
** LOG out if physics is attached to default pawn or not. GetOwner()->GetName()
122. Input Binding

InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();

if (InputComponent)
{
UE_LOG(LogTemp, Warning, TEXT("Input component found!"));
InputComponent->BindAction("Grab", IE_Pressed, this,
&UGrabber::Grab);
}

Anything to access from the permanent storage, use accessor ::


Anything to access from temporary storage,use accessors dot (.) and ->

125. Using Physics Handles

https://docs.unrealengine.com/en-US/API/Runtime/Engine/PhysicsEngine/
UPhysicsHandleComponent/index.html

127. Iteration thru Valid Actors

Linear Damping = slow down speed


Angular Damping = make heavy and sticky

#include "Components/PrimitiveComponent.h"

float UOpenDoor::TotalMassOfActors() const


{
float TotalMass = 0.f;
// find all overlapping actors.
TArray<AActor*> OverlappingActors;
PressurePlate->GetOverlappingActors(OUT OverlappingActors);

// add up their masses.


for (AActor* Actor : OverlappingActors)
{
TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()-
>GetMass();
}
return TotalMass;
128. POINTER PROTECTION PROCESS
- Horrible crash when following nullptr
- Always check pointers before used
- When declaring, always initialize to nullptr

129. SFX & Audio Clips

UAudioComponent
#include “Components/AudioComponent.h”

167. PAWNS VS CHARACTER C++

Single Click on Map - Blueprints - GameMode : GameMode Base - Select GameModeBased


Class - choose yours

168. CHARACTER MOVEMENT FUNCTIONS

AddMovementInput() // take vector -- takes which direction moving


AddControllerPitchInput() // looking up and down
AddControllerYawInput() // turn left and right
Jump()

Extension** C++ Helper -> press Ctrl + Shift + P -> type create implementation

void AShooterCharacter::SetupPlayerInputComponent(UInputComponent*
PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);

PlayerInputComponent->BindAxis(TEXT("MoveForward"), this,
&AShooterCharacter::MoveForward);
PlayerInputComponent->BindAxis(TEXT("LookUp"), this,
&APawn::AddControllerPitchInput);
PlayerInputComponent->BindAxis(TEXT("MoveRight"), this,
&AShooterCharacter::MoveRight);
PlayerInputComponent->BindAxis(TEXT("LookRight"), this,
&APawn::AddControllerYawInput);
PlayerInputComponent->BindAction(TEXT("Jump"),
EInputEvent::IE_Pressed, this, &ACharacter::Jump);
}

Controller Movement

GamePad Right Thumbstick Y-Axis


PlayerInputComponent->BindAxis(TEXT("LookUpRate"), this,
&AShooterCharacter::LookUpRate);

void AShooterCharacter::LookUpRate(float AxisValue)


{
AddControllerPitchInput(AxisValue * RotationRate * GetWorld()-
>GetDeltaSeconds());
}

170. Third Person Camera Spring Arm

Add Camera component, Add Spring Arm component, make the camera comp be the child of
spring arm, Use Pawn Control Rotation option in spring arm (for rotating 360),

171, 173. Skeletal Animations 101

RC -> animation bp ->


RC on chart -> Blend (combine 2 poses together)
Add Variable ->

174. 2D Blend Spaces

Add New - Animation - BlendSpace

ABP - Get Velocity - VectorLength -

175. SPEED

176. Inverse Transforming Vectors (IMP) Turn angle

177. CALCULATING ANIMATION SPEED

Calculating jog speed


------------------------------
start 0.16
start y 16.233488
end 0.34
end y -37.451061

-53.684549 / 0.18 = -298.2474944444444 = 320

foot_speed = (y_finish - y_start) / (t_finish - t_start)

Calculating walk speed


------------------------------
start 0.25
start y 32.761688
end 0.76
end y -30.551456

-63.313144 / 0.51 = -124.1434196078431 = 140

178. Gun Actors

Gun Component under Mesh

Create c++ class for Gun - Create blueprint subclass

private:
UPROPERTY(VisableAnywhere)
USceneComponent* Root;

UPROPERTY(VisableAnywhere)
UStaticMeshComponent* Mesh;
OR
USkeletalMeshComponent* Mesh; (depends on the weapon mesh type)

Header --
#include "Components\StaticMeshComponent.h"
#include "Components\SkeletalMeshComponent.h"

.cpp

AGun::AGun()
{
// Set this actor to call Tick() every frame. You can turn this off
to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

// Adding components in the Blueprint class


Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
SetRootComponent(Root);

Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh"));
Mesh->SetupAttachment(Root);
}

180. Attaching To Meshes Via Sockets

To hide default weapon - SkinnedMeshComponent.h - HideBoneByName()

GetMesh()->HideBoneByName(TEXT("weapon_r"), EPhysBodyOp::PBO_None);

After default weapon is hidden, add socket


RC on the default weapon - add socket -

181. Shooting Architecture

GamePlayStatics.h - SpawnEmitterAttached(...)

182. Spawning Particle Effect

Open weapon mesh - Skeleton Tree on left pane - MuzzleFlashSocket

UPROPERTY(EditAnywhere)
UParticleSystem* MuzzleFlash;

void AGun::PullTrigger()
{
//UE_LOG(LogTemp, Warning, TEXT("You've been shot!"));
UGameplayStatics::SpawnEmitterAttached(MuzzleFlash, Mesh,
TEXT("MuzzleFlashSocket"));
}

183. Player View Point


#include "DrawDebugHelpers.h" // debugging
DrawDebugCamera(GetWorld(), GetActorLocation(), GetActorRotation(),
90, 2.f, FColor::Green, true); // aiming point camera

Check Controller.h - GetPlayerViewPoint(Location, Rotation);

184. Line Tracing By Channel

LineTraceTestByChannel()

Project Setting - Engine - Collision - Trace Channel - new Trace Channel -

Calculating bullet end point


FVector EndPoint = Location + Rotation.Vector() * MaxRange;

In DrawDebugHelpers.h

FHitResult Hit;
bool bSuccess = GetWorld()->LineTraceSingleByChannel(Hit, Location,
EndPoint, ECollisionChannel::ECC_GameTraceChannel1);
if (bSuccess)
{
DrawDebugPoint(GetWorld(), Hit.Location, 20, FColor::Green, true);
}

185. Impact Effect

GamePlayStatics.h

SpawnEmitterAtLocation(..)

FVector ShotDirection = -Rotation.Vector(); // direction going out


DrawDebugPoint(GetWorld(), Hit.Location, 20, FColor::Green, true);
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactEffect,
Hit.Location, ShotDirection.Rotation());

186. Damage

Actor.h - TakeDamage()

FRadialDamageParams = Generade
FPointDamageEvent = Single target
188. Overriding TakeDamage
virtual float TakeDamage(float DamageAmount, struct FDamageEvent
const& DamageEvent, class AController* EventInstigator, AActor*
DamageCauser) override;

189. Blending Animations By Booleans

Blend Poses by bool node in BP

192. AI Aiming

AIController.h

SetFocus(PlayerPawn)

#include “Kismet/GameplayStatics.h”
GameplayStatics.h for UGameplayStatics::GetPlayerPawn()
APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
SetFocus(PlayerPawn);

193. Nav Mesh And AI Movement

AIController.h - MoveTo()

void AShooterAIController::Tick(float DeltaSeconds)


{
Super::Tick(DeltaSeconds);

APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);


MoveToActor(PlayerPawn, 200.f);
}

194. Checking AI Line Of Sight

AIController.h - LineOfSightTo()

To stop chasing AI
virtual void ClearFocus(EAIFocusPriority::Type InPriority);

if (LineOfSightTo(PlayerPawn))
{
SetFocus(PlayerPawn);
MoveToActor(PlayerPawn, ChaseRadius);
}

195. BehaviorTrees And Blackboards

class UBehaviorTree* AIBehavior;

RunBehaviorTree()

if (AIBehavior != nullptr)
{
RunBehaviorTree(AIBehavior);
}

Add Sequence Node in BT.

196. Setting Blackboard Keys In C++

Set a new key - AIController.h - GetBlackboardComponent()

BlackboardComponent.h - setValueAs … ()

GetBlackboardComponent()->SetValueAsVector(TEXT("PlayerLocation"),
PlayerPawn->GetActorLocation());

197. Behavior Tree Tasks And Sequences

Controller.h - GetPawn()

GetBlackboardComponent()->SetValueAsVector(TEXT("StartLocation"),
GetPawn()->GetActorLocation());

198. BT Decorators And Selectors

ClearValue() -- to clear player location

GetBlackboardComponent()->ClearValue(TEXT("PlayerLocation"));

199. Custom BTTasks In C++

New C++ - Bttask_blackboard - add “GameplayTasks” in the name.Build.cs file.


Create constructor - and in its definition - NodeName = TEXT("Clear Blackboard Value");

200. Executing BTTasks

BTTask_BlackboardBase.h
BTTaskNode.h

BehaviorTreeTypes.h

EBTNodeResult::Type
UBTTask_ClearBlackboardValue::ExecuteTask(UBehaviorTreeComponent
&OwnerComp, uint8* NodeMemory)
{
Super::ExecuteTask(OwnerComp, NodeMemory);

OwnerComp.GetBlackboardComponent()-
>ClearValue(GetSelectedBlackboardKey());
return EBTNodeResult::Succeeded;
}

201. BTTasks That Use The Pawn

202. BTServices In C++

Add default focus service in the node.

204. Ending The Game

DetachFromControllerPendingDestroy();
GetCapsuleComponent()-
>SetCollisionEnabled(ECollisionEnabled::NoCollision);
AFirstShooterGameModeBase* GameMode = GetWorld()-
>GetAuthGameMode<AFirstShooterGameModeBase>();
if(GameMode != nullptr)
{
GameMode->PawnKilled(this);
}
Blueprint Class

Flip Flop - for flashlight and stuff


Gate - Door and stuff
TestInput - Mouse Events
Make Rotator : (camera movement)
X - Yaw - left and right
Y - Pitch - up and down

Add Movement Input :

Structures (Struct)
Transform, Hit Result,

You might also like