Videogames UE4 Development

UE4 and Git-LFS

We have a project setup right here on GitHub.

UE4 C++

Crash course: Converting Blueprints to C++. Documentation: Gameplay Architecture.

Common includes

Class #include
UWorld Engine/World.h
AActor GameFramework/Actor.h
UActorComponent Components/ActorComponent.h
USceneComponent Components/SceneComponent.h
UGameplayStatics Engine/World.h
UKismetSystemLibrary Kismet/GameplayStatics.h
UKismetMathLibrary* Kismet/KismetMathLibrary.h
FMath Math/UnrealMathUtility.h
UPhysicsHandleComponent PhysicsEngine/PhysicsHandleComponent.h
  • (*) KismetMath is usually a wrapper to FMath. Review implementation and try to call directly FMath.

Mapping types

Blueprint C++
String FString
Name FName
Vector FVector
Rotator FRotator
Transform FTransform
Object UObject*
Actor AActor*
ActorComponent UActorComponent*
Float float
- double
Integer int32
- uint32
Integer64 int64
- uint64
Bool bool

Properties Visibility

  • Blueprint:
    • BlueprintReadonly
    • BlueprintReadWrite
  • Defaults and instance:
    • VisibleAnywhere
    • EditAnywhere
  • Only defaults:
    • VisibleDefaultsOnly
    • EditDefaultsOnly
  • Only instance:
    • VisibleInstanceOnly
    • EditInstanceOnly

Tips

  • You can create C++ files either manually or using the UE4 editor, first case requires to regenerate project files (left click on .uproject Generate Visual Studio Project Files).
  • After syncing files with Git, it’s a good idea to regenerate project files.
  • If Hot reloading doesn’t seem to take your changes, close editor and Rebuild project.
  • How to found BP nodes? Put your mouse over the node, see target and try to lookup for the file and lastly search for some keyword on the function name. For example:

    UE4 find Blueprint nodes on C++

Useful tools

To clone your Azure repos with Github Desktop follow this guide.

Delegate samples

/* DECLARATION */
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCompletedQuestSignature, int32, index)

UPROPERTY(BlueprintAssignable, BlueprintCallable)
FCompletedQuestSignature CompletedQuest;

/* BROADCAST */
CompletedQuest.Broadcast(parameter);

/* SUBSCRIBE */
UFUNCTION() // Required for dynamic
void FunctionHandler(int32 index)

CompletedQuest.AddDynamic(this, &Class::FunctionHandler);
CompletedQuest.Add // For non dynamic version

Vector samples

Forward unit vector from a given rotation.

GetComponentRotation().Vector()

Calculate vector of size MaxDistance starting at actor/component location on the same rotation as the actor/component.

FVector UClass::GetMaxGrabLocation() const
{
        // GetComponentLocation or GetLocation depending if you're on an Actor or Component
        // same with Rotation
	return GetComponentLocation() + GetComponentRotation().Vector() * MaxDistance;
}

Raytracing samples

TODO

Sweep samples

// Params with ignore self
FCollisionQueryParams TraceParams(FName("SphereTrace"), false, GetOwner());
FHitResult OutHit;

// Sweep for ECC_PhysicsBody or ECC_WorldDynamic
if(GetWorld()->SweepSingleByObjectType(
	OutHit, GetComponentLocation(), GetMaxGrabLocation(), FQuat::Identity,
        FCollisionObjectQueryParams(ECC_TO_BITFIELD(ECollisionChannel::ECC_PhysicsBody) | ECC_TO_BITFIELD(ECollisionChannel::ECC_WorldDynamic)), 
        FCollisionShape::MakeSphere(GrabRadius), TraceParams)) {
        // Handle hit!
}

Anim notifiers C++

 UCLASS()
 class YOURPROJECT_API UAnimNotify_Name : public UAnimNotify
 {
     GENERATED_BODY()
        
 protected:

     virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;        
 };
    
 void UAnimNotify_Name::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
 {
     Super::Notify(MeshComp, Animation);

     // YOUR CODE GOES HERE
 }

More info.

UE4 Plugins

UE4 Animation

Documentation: Animation

UE4 AI

Official docs

  • To enable the debugger set a key binding in Project Settings > Engine - Gameplay Debbuger > Activation Key. If you’re using a non default US keyboard or a keyboard with international bindings, it is recommended to set a plain key as Asterisk (*) or Minus (-), instead of something like an Apostrophe (‘) that won’t be triggered by a single key-press on a US-International setup.
  • RecastNavMesh: update some navmesh settings on the scene. Also update-able from the project settings window searching for the option Agent (you can add support for multiple types of agents from here).

  • Navmesh modifier volume: Adds additional information to the navmesh. Exmample: high cost areas, not allowed areas, etc.

  • To disable Auto-updates: Editor Preferences -> Level Editor -> Misc -> Update Navigation Automatically.

  • More info: Official docs

AI Perception

Official docs

Behavior trees

Official docs

  • Quick Start Guide

  • Nodes: Official reference

    • Composite Nodes: These are the nodes that define the root of a branch and the base rules for how that branch is executed.
    • Task Nodes: These are the leaves of the Behavior Tree, these nodes are the actionable things to do and don’t have an output connection.
    • Decorator Nodes: Also known as conditionals. These attach to another node and make decisions on whether or not a branch in the tree, or even a single node, can be executed.
    • Service Nodes: These attach to Composite nodes, and will execute at their defined frequency as long as their branch is being executed. These are often used to make checks and to update the Blackboard. These take the place of traditional Parallel nodes in other Behavior Tree systems.

Environment Query System (EQS)

Official Docs

UE4 AI movement C++

See this tutorial: https://www.vikram.codes/blog/ai/01-basic-navigation Improved and updated code to seek for a Random Reachable Location in the Navmesh:

How to do it?

  • Convert Mouse Location to World Space: Interact with 3D objects using players’ mouse. See video
  • Reducing Packaged Game Size: See here

Equilaterus (CC-BY) 2018 - 2019.