Skip to content

Instantly share code, notes, and snippets.

@rbento
Last active June 28, 2024 09:12
Show Gist options
  • Save rbento/3dcea69235fba513b02e33a055127253 to your computer and use it in GitHub Desktop.
Save rbento/3dcea69235fba513b02e33a055127253 to your computer and use it in GitHub Desktop.

Unreal Engine 5

Configuring VCS - Git

Sample .gitattributes file

Content/** filter=lfs diff=lfs merge=lfs -text

Using Git LFS with assets

git lfs install
git add .gitattributes

Sample .gitignore file as generated via Unreal Engine 5

Binaries
DerivedDataCache
Intermediate
Saved
.vscode
.vs
*.VC.db
*.opensdf
*.opendb
*.sdf
*.sln
*.suo
*.xcodeproj
*.xcworkspace

Sample .gitignore file as generated via GitHub

# Visual Studio 2015 user specific files
.vs/

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
*.ipa

# These project files can be generated by the engine
*.xcodeproj
*.xcworkspace
*.sln
*.suo
*.opensdf
*.sdf
*.VC.db
*.VC.opendb

# Precompiled Assets
SourceArt/**/*.png
SourceArt/**/*.tga

# Binary Files
Binaries/*
Plugins/*/Binaries/*

# Builds
Build/*

# Whitelist PakBlacklist-<BuildConfiguration>.txt files
!Build/*/
Build/*/**
!Build/*/PakBlacklist*.txt

# Don't ignore icon files in Build
!Build/**/*.ico

# Built data for maps
*_BuiltData.uasset

# Configuration files generated by the Editor
Saved/*

# Compiled source files for the engine to use
Intermediate/*
Plugins/*/Intermediate/*

# Cache files for the editor to use
DerivedDataCache/*

Custom .gitignore complemented by .p4ignore

# Visual Studio user settings files that should be ignored.
.vs/
*.pdb
*-Debug.*

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
*.ipa

# These project files can be generated by the engine
*.xcodeproj
*.xcworkspace
*.sln
*.suo
*.opensdf
*.sdf
*.VC.db
*.VC.opendb

# Precompiled Assets
SourceArt/**/*.png
SourceArt/**/*.tga

# Binary Files
Binaries/*
Plugins/*/Binaries/*
obj/

# Builds
Build/*

# Whitelist PakBlacklist-<BuildConfiguration>.txt files
!Build/*/
Build/*/**
!Build/*/PakBlacklist*.txt

# Don't ignore icon files in Build
!Build/**/*.ico

# Built data for maps
*_BuiltData.uasset

# User-specific or configuration files generated by the Editor
Saved/*
FileOpenOrder/*

# Compiled source files for the engine to use
Intermediate/*
Plugins/*/Intermediate/*

# Cache files for the editor to use
DerivedDataCache/*

Configuring VCS - Perforce

Perforce Command Line

System Information

p4 info
p4 admin sysinfo

Configuring Perforce Typemap

Open Typemap file for editing

p4 typemap

Sample Typemap for Unreal Engine 5

Typemap:
    binary+w //....exe
    binary+w //....dll
    binary+w //....lib
    binary+w //....app
    binary+w //....dylib
    binary+w //....stub
    binary+w //....ipa
    binary+l //....uasset
    binary+l //....umap
    binary+l //....upk
    binary+l //....udk
    binary+l //....ubulk
    binary+wS //..._BuiltData.uasset

Ignoring Files

Sample .p4ignore File as per the Unreal Engine 5 documentation

# User-specific folders or temporary files that should not be versioned.
Saved/
Intermediate/
DerivedDataCache/
FileOpenOrder/
obj/

# Certain file types that should not be versioned.
*.pdb
*-Debug.*

# Visual Studio user settings files that should be ignored.
.vs/

Custom .p4ignore complemented by .gitignore

# Visual Studio user settings files that should be ignored.
.vs/
*.pdb
*-Debug.*

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
*.ipa

# These project files can be generated by the engine
*.xcodeproj
*.xcworkspace
*.sln
*.suo
*.opensdf
*.sdf
*.VC.db
*.VC.opendb

# Precompiled Assets
SourceArt/**/*.png
SourceArt/**/*.tga

# Binary Files
Binaries/*
Plugins/*/Binaries/*
obj/

# Builds
Build/*

# Whitelist PakBlacklist-<BuildConfiguration>.txt files
!Build/*/
Build/*/**
!Build/*/PakBlacklist*.txt

# Don't ignore icon files in Build
!Build/**/*.ico

# Built data for maps
*_BuiltData.uasset

# User-specific or configuration files generated by the Editor
Saved/*
FileOpenOrder/*

# Compiled source files for the engine to use
Intermediate/*
Plugins/*/Intermediate/*

# Cache files for the editor to use
DerivedDataCache/*

Test Whether File Is Ignored

p4 ignores -i -v Main_ThirdPerson\Intermediate\file.pdb

c:\Perforce\Workspace\Main_ThirdPerson\Intermediate\file.pdb not ignored

Set P4IGNORE

Configuring it via Environment Variables have precedence over setting it via the command below:

p4 set P4IGNORE=C:\Users\YourName\.p4ignore

Test whether files are ignored

p4 ignores -i -v Main_ThirdPerson\Intermediate\file.pdb

c:\Perforce\Workspace\Main_ThirdPerson\Intermediate\file.pdb ignored by C:\Users\YourName.p4ignore:9:*.pdb

Windows Defender Virus & Thread Protection

Compiling shaders may take too long due to Windows Defender Virus & Thread Protection monitoring.

To avoid that, add the following programs to the process exclusion list:

devenv.exe
unrealeditor.exe
livecodingconsole.exe
shadercompileworker.exe

Missing UnrealBuildTool

A missing UnrealBuildTool.dll error may arise while clicking Tools > Generate Visual Studio Project after atempting to open a Unreal project from a newly created workspace.

That being the case, open the UnrealBuildTool solution and build it for Release:

C:\Program Files\Epic Games\UE_5.3\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.sln

Deleting a stream depot

While attempting to delete a stream depot, an error message may suggest there are still streams associated with a depot even thought they do not show up in the P4 Admin interface. In that case, proceed via Command Prompt:

List all stream depots

p4 streams -a

Obliterate the dangling stream

p4 stream --obliterate -y  //ThirdPerson/Main

Now proceed to deleting the depot via P4 Admin.

Avoiding Tearing In the Editor

Tearing may occur in the editor even when running with a good graphics card such as NVidia GeForce RTX 4090 depending on the relation between graphics card and monitor or laptop screen refresh rate, as observed with a Lenovo ThinkPad P6 (Core i9, 96Gb RAM, RTX 4090, OLED 3K 60Hz Display)

One approach to avoid it is to turn on VSync in the Unreal Editor via command line which will lock the update frequency to the display refresh rate.

r.VsyncEditor 1

Launch Game - Standalone

  • Launch the game fullscreen
  • Launch a separate Command Prompt window with the game logs
Default Map
"C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\Win64\UnrealEditor.exe" "%USERPROFILE%\Documents\Unreal Projects\GameTitle\GameTitle.uproject" -game -log
Specific Map
"C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\Win64\UnrealEditor.exe" "%USERPROFILE%\Documents\Unreal Projects\GameTitle\GameTitle.uproject" /Game/<Content/MapPath>/<MapName> -game -log

Launch Game - Server

  • Launch the server in a separate Command Prompt window
Default Map
"C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\Win64\UnrealEditor.exe" "%USERPROFILE%\Documents\Unreal Projects\GameTitle\GameTitle.uproject" -server -log
Specific Map
"C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\Win64\UnrealEditor.exe" "%USERPROFILE%\Documents\Unreal Projects\GameTitle\GameTitle.uproject" /Game/<Content/MapPath>/<MapName> -server -log

Launch Game - Client

  • Launch the game fullscreen
  • Join the specified server
  • Launch a separate Command Prompt window with the game logs
"C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\Win64\UnrealEditor.exe" "%USERPROFILE%\Documents\Unreal Projects\GameTitle\GameTitle.uproject" 127:0.0.1:7777 -game -log

See also: command-line-arguments-in-unreal-engine

Under The Hood

When playing a game in the editor

  1. Unreal loads the Map
  2. The Map specifies a GameMode
  3. The PlayerController joins the Map
  4. The PlayerController asks the GameMode to spawn a Pawn
  5. The Pawn is linked to the PlayerController

Logging

To Output

    UE_LOG(LogTemp, Display, TEXT("Message"));

To Screen

    UEngine *Engine = GetEngine();
    check(Engine != nullptr);
    
    Engine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Message"));

Creating An Interactive Console Function

C++ Header
    UFUNCTION(Exec)
    void Host(const FString& Map) const;
Console
Host Main

On Multiplayer

References
GameMode
  • The GameMode object only exists on the server
GameInstance
  • Each Game Server/Client has a separate GameInstance object
    • Constructor is called both when playing in the editor and when playing standalone
    • Init only called when playing standalone
ServerTravel
  • Moves all connected player controllers to the new level
    UWorld* World = GetWorld();
    check(World != nullptr);

    FString URL = "/Game/<GameProjectName>/Maps/";
    URL.Append(Map);
    URL.Append("?listen");

    World->ServerTravel(URL);
ClientTravel
  • Moves a single PlayerController to a target IP address or Map
    APlayerController* PlayerController = GetFirstLocalPlayerController();
    check(PlayerController != nullptr);

    PlayerController->ClientTravel(Address, ETravelType::TRAVEL_Absolute);

Events

Blueprint Implementable Event

  • Defined in C++
  • Implemented in Blueprints
  • Usage
    • An event is expected to be called in C++ but is implemented in Blueprints
    • Game-specific behaviours and interactions

Door.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Door.generated.h"

UCLASS()
class DELIBERATE_API ADoor : public AActor
{
	GENERATED_BODY()
protected:
	UFUNCTION(BlueprintImplementableEvent)
	void OnOpen();

	UFUNCTION(BlueprintImplementableEvent)
	void OnClose();
};

Door.cpp

#include "Door.h"

Blueprint Native Event

  • Similar to Blueprint Implementable Event
  • Adds a default implementation in C++
    • Can be overriden by a Blueprint implementation

Chest.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Chest.generated.h"

UCLASS()
class DELIBERATE_API AChest : public AActor
{
	GENERATED_BODY()
protected:
	UFUNCTION(BlueprintNativeEvent)
	void OnOpen();
};

Chest.cpp

#include "Chest.h"

void AChest::OnOpen_Implementation() 
{
    // Default Implementation
}

Delegate Events

Handle the communication between multiple unrelated actors with decoupled approach.

Allow objects to dynamically subscribe and handle game events

Actor 1 : Defines a Event (Dispatcher)

Actor 2 : Subscribes to Actor 1 Event (Bind to that Event Dispatcher. Gets added to that Event Dispatcher subscriber's list) Actor 3 : Subscribes to Actor 1 Event (Bind to that Event Dispatcher. Gets added to that Event Dispatcher subscriber's list)

Actor 1 : Publishes an Event (Sends an Event as a Message to the Dispatcher)

That Event Dispatcher then loops through its subscriber's list and calls that Event handler on each subscriber. As a result:

Actor 2 : Gets notified of the event and has a chance the handle it.
Actor 3 : Gets notified of the event and has a chance the handle it.

Multiple Delegate types are supported

  • Singlecast
  • Multicast
  • Dynamic
  • Non-Dynamic

All types are declared via macros:

  • DECLARE_MULTICAST_DELEGATE_OneParam(<delegate_name>, <param_type>)
  • DECLARE_MULTICAST_DELEGATE_TwoParams(<delegate_name>, <param_type>, <param_type>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment