GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things to Come
-
Upload
gerke-max-preussner -
Category
Software
-
view
282 -
download
14
Transcript of GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things to Come
Then…
• “We ain’t gonna need it”
• Fixed, rigid feature set
• First Person Shooter centric
• Programmer centric
• Closed source
• Monolithic, aged code base
• Secret development schedule
• PC & console focused
• Millions of $ studio licenses
Now…
• “You might need it”
• Plug-ins and customizable tools
• Game type agnostic
• Artist & game designer friendly
• Public source
• Modular code base, largely rewritten
• Public feature voting on trello.com
• Seamless multi-platform development
• $19/month subscription
Unreal Engine in 2014
Unreal Engine in 2014
Engine Overview
The Big Picture
Directories
Configuration
Modules
Projects
Root Directory
• /Engine – All code, content & configuration for the Engine
• /MyProject – All files for the game project ‘MyProject’
• /Templates – Templates for creating new projects
Inside the /Engine and Project Directories
• /Binaries – Executables & DLLs for the Engine
• /Build – Files needed for building the Engine
• /Config – Configuration files
• /Content – Shared Engine content
• /DerivedDataCache – Cached content data files (Engine only)
• /Intermediate – Temporary build products (Engine only)
• /Plugins – Shared and project specific plug-ins
• /Saved – Autosaves, local configs, screenshots, etc.
• /Source – Source code for all the things!
The Big Picture
Directories
Configuration
Modules
Projects
INI Files
• Hold class default properties
• Will be loaded into CDOs on startup
• Organized in a hierarchy
• Higher INIs override lower ones
• Organized in sections
• Key-value pairs within sections
• Important ones exposed in Editor UI
• Low-level access with FConfig
The Big Picture
Directories
Configuration
Modules
Projects
INI Files
• Hold class default properties
• Will be loaded into CDOs on startup
• Organized in a hierarchy
• Higher INIs override lower ones
• Organized in sections
• Key-value pairs within sections
• Important ones exposed in Editor UI
• Low-level access with FConfigClass Constructor
BaseXXX.ini
DefaultXXX.ini
XXX.ini
Editor & Project Settings
The Big Picture
Directories
Configuration
Modules
Projects
Modularity Promotes
• Reusability
• Extensibility
• Maintainability
• Decoupling
• Efficiency
Monolithic builds are
still possible though!
The Big Picture
Directories
Configuration
Modules
Projects
Module Types
• Developer – Used by Editor & Programs, not Games
• Editor – Used by Unreal Editor only
• Runtime – Used by Editor, Games & Programs
• ThirdParty – External code from other companies
• Plugins – Extensions for Editor, Games, or both
• Programs – Standalone applications & tools
Module Dependency Rules
• Runtime modules must not have dependencies to Editor or Developer modules
• Plug-in modules must not have dependencies to other plug-ins
The Big Picture
Directories
Configuration
Modules
Projects
Module TypeUnrealEd App Game
Runtime √ √ √
ThirdParty √ √ √
Plugins √ √ √
Developer √ √ X
Editor √ X X
Module usage across different types of applications
The Big Picture
Directories
Configuration
Modules
Projects
Important Modules for Beginners
• Core – Fundamental core types & functions
• CoreUObject – Implements the UObject sub-system
• Engine – Game classes & engine framework
• OnlineSubsystem – Online & social networking features
• Slate – Widget library & high-level UI features
The Big Picture
Directories
Configuration
Modules
Projects
Interesting Modules for Advanced Programmers
• DesktopPlatform – Useful APIs for Windows, Mac & Linux
• DetailCustomizations – Editor’s Details panel customizations
• Launch – Main loop classes & functions
• Messaging – Message passing sub-system
• Sockets – Network socket implementations
• Settings – Editor & Project Settings API
• SlateCore – Fundamental UI functionality
• TargetPlatform – Platform abstraction layer
• UMG – Unreal Motion Graphics implementation
• UnrealEd – Unreal Editor main frame & features
The Big Picture
Directories
Configuration
Modules
Projects
Interesting Modules for Cool Features
• Analytics – Collects usage statistics from Editor & games
• AssetRegistry – Database for assets in Unreal Editor
• GameLiveStreaming – Twitch Streaming
• HeadMountedDisplay – HMD Support API (Oculus, etc.)
• JsonUtilities & XmlParser – Handle Json & XML files
• SourceControl – API for custom source control providers
The Big Picture
Directories
Configuration
Modules
Projects
Your Game Projects can…
• Use Blueprints, C++ Code or both
• Contain any number of modules & plug-ins
• Be moved around and shared with others
Project Templates to Get You Started
• Blank (with or without sample content)
• First Person Shooter
• Side scroller, top-down & puzzle games
• Flying & driving games
• They all come in Blueprint and C++ flavors
• More to come, and make your own!
Project Templates & Samples
Project Packaging & Deployment
Game Framework
Game Framework History
UE1 and UE2
• Designed for First Person Shooters (FPS)
• UnrealScript game scripting language
UE3
• Kismet Visual Scripting added
• More modular game classes
• But still very FPS centric
UE4
• UnrealScript replaced with Blueprints
• Game genre agnostic
• Lots of sample projects!
UnrealScript vs. C++ vs. Blueprints
UnrealScript was:
• An object-oriented scripting language
• Similar in syntax to C, C++, Java, but also somewhat different
• Compiled to virtual machine byte code
• Adding interesting features, such as States, Timers, Delegates
Blueprints are:
• A visual scripting system that is artist and designer friendly
• Using the same virtual machine as UnrealScript
• Almost as powerful as UnrealScript, and in many ways better
C++ has:
• Always been part of UE game programming
• Tight bi-directional integrations with the virtual machine
• Been greatly improved in UE4 to replace UnrealScript for codersC++
Blueprints
VM
So What Is The Game Framework?
Overview
Why Use It?
Set Of Foundation Classes
• Provide basic structure and functions of your game
• You derive from the classes that you need
• Fill in the details for your particular game
What’s Missing?
• Game genre specific implementations
• No concept of health and death
• No built-in classes for weapons, inventory, etc.
So What Is The Game Framework?
Overview
Why Use It?
Reduced Learning Curve
• Hides the low-level details of game engines
• Benefit from 20+ years of game developing experience
• Many samples and tutorials for solving common tasks
High Productivity
• Focus on what really matters to you: making your game
• Solves many tricky problems in games (movement, input, etc.)
• Greatly reduces boilerplate code needed for all games
Scalability
• Smoothly grow your game & team from prototype to AAA
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
What is an Actor?
• Entity in a game level
• Usually contains one or more Actor Components
• Supports network replication for multiplayer games
Things to know about Actors
• Don’t have Location, Rotation (stored in root component)
• Created with SpawnActor() method
• Must be destroyed explicitly with Destroy() method
• Will not be garbage collected during the game
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
What is an ActorComponent?
• Reusable functionality that can be added to an Actor
• Contain the most interesting functionality & events
Example Components:
• Scene Component – Adds transforms and attachments
• Primitive Component – Adds collision and rendering
• UAudioComponent, UArrowComponent,
UInputComponent, ULightComponent, UMeshComponent,
UParticleSystemComponent and many more!
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
PrimiviteComponent Event Examples
• Hit – Called when bumping into a wall
• Begin/EndOverlap – Walk into or out of a trigger
• Begin/EndCursorOver
• Clicked/Released
• InputTouchBegin/End
• Begin/EndTouchOver
Also accessible in Blueprints!
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
What is a Pawn?
• An agent in the world
• Optionally possessed by a Controller
• Usually handles movement and input
Things to know about Pawns
• Good place to implement health
• No movement or input code by default
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
What is a Character?
• Special Pawn that can walk
• Comes with useful Components
Things to know about Controllers
• Handles collision
• Client-side movement prediction
• Much improvement from UE3
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
What is a Controller?
• A brain that can possess a Pawn
• PlayerController: Represents a human player
• AIController: Computes AI behavior for Pawns
Things to know about Controllers
• Possess one Pawn at a time
• Can persist after possessed Pawn dies
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
PlayerController
• Interface for players to agents
• Handles touches, clicks, keyboard
• Showing/hiding mouse cursor
• Good place for non-agent code
• Menus, voice chat, etc.
• Many other useful options
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
What is a HUD?
• Head-Up Display
• Responsible for in-game UI
Things to know about Controllers
• Immediate-mode drawing API
• No tools for building HUDs
• UMG will provide all the things!
Fundamental Concepts
Actors
Components
Pawn
Character
Controller
HUD
GameMode
What is a GameMode?
• Implements the game rules
• Configures default classes for Pawn, Controller, HUD, etc.
• Can be accessed from anywhere (GetGameMode())
Things to know about GameModes
• Only exists on the server and single player instances!
• GameState is used to replicate game state to clients
• Default game mode can be set in Project Settings
• Per-map overrides in World Settings
Other Important Concepts
Input
Collision
Replication
Axes & Actions
• Can bind to mouse, keyboard, touch, etc.
• Defined in Project Settings
Input Processing Order
1. PlayerController
2. Level Blueprint
3. Possessed Pawn
Other Important Concepts
Input
Collision
Replication
Various Collision Query Functions
• Line traces (ray casts)
• Geometry sweeps
• Overlap tests
Simple Collision
• Box, sphere, capsule, convex
• Authoring tools in Editor
• Used for movement, physics, etc.
Complex collision
• Actual graphics triangles
• Used for weapons, kinematics, etc.
Other Important Concepts
Input
Collision
Replication
Transfer game state between Server and Clients
• Remote Procedure Calls (RPC)
• Data transfer (variables, structs, dynamic arrays)
• Editor supports multiplayer PIE testing
Game Framework Flowchart
Slate UI Framework
UE1, UE2 and UE3
Slate Design & Principles
Overview
Features
Concepts
Tools
Architecture
• Written entirely in C++
• Platform agnostic (works on mobile and consoles, too!)
• SlateCore module provides low-level functionality
• Slate module contains library of common UI widgets
• Does not require Engine or Editor modules
Current Use Cases
• Unreal Editor
• Standalone desktop applications
• Mobile applications
• In-game UI
Slate Design & Principles
Overview
Features
Concepts
Tools
Styling
• Customize the visual appearance of your UI
• Images (PNGs and Materials), Fonts, Paddings, etc.
• Customizable user-driven layouts
Input Handling
• Keyboard, mouse, joysticks, touch
• Key bindings support
Render Agnostic
• Supports both Engine renderer and standalone renderers
Large Widget Library
• Layout primitives, text boxes, buttons, images, menus, dialogs, message boxes, navigation, notifications, dock tabs, list views, sliders, spinners, etc.
Slate Design & Principles
Overview
Features
Concepts
Tools
Declarative Syntax
• Set of macros for declaring widget attributes
• Avoids layers of indirection
Composition
• Compose entire widget hierarchies in a few lines of code
• Uses fluent syntax for ease of use
• Preferred over widget inheritance
• Any child slot can contain any other widget type
• Makes it very easy to rearrange UIs in code
// Example custom button (some details omitted)
class STextButton
: public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SMyButton )
{ }
// The label to display on the button.
SLATE_ATTRIBUTE(FText, Text)
// Called when the button is clicked.
SLATE_EVENT(FOnClicked, OnClicked)
SLATE_END_ARGS()
// Construct this button
void Construct( const FArguments& InArgs );
};
// Button implementation (some details omitted)
void STextButton::Construct ( const FArguments& InArgs )
{
ChildSlot
[
SNew(SButton)
.OnClicked(InArgs._OnClicked)
[
SNew(STextBlock)
.Font(FMyStyle::GetFontStyle(“TextButtonFont"))
.Text(InArgs._Text)
.ToolTipText(LOCTEXT(“TextButtonToolTip", “Click Me!"))
];
];
}
Slate Design & Principles
Overview
Features
Concepts
Tools
Widget Inspector
• Visually debug and analyze your UI
• Can jump directly to widget code in Visual Studio or XCode
UDK Remote
• iOS app for simulating touch devices on your PC
• Remote server is a plug-in (enabled by default)
• Primarily used for game development
Demo
Demo
Going A Little Deeper
State Updates
Widget Roles
Anatomy
Attributes
Polling instead of Invalidation
• Avoids duplicate state data
• Exception: Non-trivial data models (use caches instead)
• Performance depends on number of visible widgets
Going A Little Deeper
State Updates
Widget Roles
Anatomy
Attributes
Fundamental Widget Types
• SCompoundWidget – Can have nested child widgets
• SLeafWidget – Does not contain child widgets
• SPanel – Base class for layout panels
Special Widgets
• SWidget – Root base class for all widgets (do not inherit!)
• SNullWidget – Empty default widget
User Widgets
• More efficient in terms of compile time
Going A Little Deeper
State Updates
Widget Roles
Anatomy
Attributes
Common Interfaces
• Arguments – Widget parameters that do not change
• Attributes – Parameters that are polled
• Event handlers – Usually named ‘OnSomeEvent’
Common Internals
• ComputeDesiredSize() - Calculates widget’s desired size
• ArrangeChildren() - Arranges children within allotted area
• OnPaint() – Draws the widget
Going A Little Deeper
State Updates
Widget Roles
Anatomy
Attributes
Common Attributes
• Enabled state, Visibility, Hit testability
• Tooltip Widget, Tooltip Text, Cursor Style
• Horizontal & Vertical Alignment , Padding
Attributes Can Be:
• Constants, i.e. IsEnabled(false)
• Delegate bindings,
i.e. IsEnabled(this, &SMyWidget::HandleIsEnabled)
Current In-Game UI Features
HUD Canvas
VP Widgets
Game Menus
FCanvas
• Low-level C++ API for drawing directly to the screen
• Has been part of Unreal Engine for many years
• All functions are in FCanvas class
• DrawText(), DrawTexture(), DrawTile(), etc.
• Use AHUD.Canvas to access the canvas object
HHitProxy
• Provides basic interaction support for FCanvas
• Create one hit proxy per interactive object
• Hit proxy ID is sent to GPU for per-pixel hit tests
Current In-Game UI Features
HUD Canvas
VP Widgets
Game Menus
UGameViewportClient
• Allows usage of Slate widgets inside game view port
• Use all features of Slate (except SWindow)
• Add/RemoveViewportWidgetContent()
Things to keep in mind
• All added widgets will be layered on top of each other (SOverlay)
• Widgets should use TWeakObjPtr for UObject references
Current In-Game UI Features
HUD Canvas
VP Widgets
Game Menus
The Hard Way
• Use FCanvas to draw your own menus
• Not recommended
The Custom Way
• Use HUD Widgets to create any menu layout
The Lazy Way
• Use GameMenuBuilder for paged menus
• FGameMenuPage - Single menu page
• FGameMenuItem - An option in a menu page
• Can be customized and styled
• Mostly used for settings screens
Unreal Motion Graphics (UMG)
Unreal Motion Graphics
Overview
Scripting
Upcoming
One UI Solution To Rule Them All
• Built on top of Slate
• Adds real-time animation and transformation to widgets
• Integrated with Blueprints
• WYSIWYG Editor for artists and designers
• No programming required (unless you want to)
• Not officially released yet, but already in the code base
Unreal Motion Graphics
Overview
Scripting
Upcoming
Adding Behavior to your UI
• Designers should not have to write code!
• Blueprints allow scripting of UI
• You can still use C++ as well, but probably won’t
Unreal Motion Graphics
Overview
Scripting
Upcoming
Currently working on:
• Materials!
• Style assets
• 2D Transforms
• Special effects
• In-world 3D UI
• Workflow polish
Arbitrary 2D Transforms
• Attachable UI Actor Components
• Injected into render stream
• Can intersect with world geometry
• Render to texture (optional)
• 3D Transformations
In-World 3D User Interfaces
Extensibility
Why Do We Want Extensibility?
Custom Requirements
• Features that are too specific to be included in UE4
• Features that UE4 does not provide out of the box
Third Party Technologies
• Features owned and maintained by other providers
• Scaleform, SpeedTree, CoherentUI, etc.
Flexibility & Maintainability
• More modular code base
• Easier prototyping of new features
How To Extend The Engine
General
Games
Editor
Plug-ins
UE3: Engine Code Changes
• Only accessible to licensees
• Required deep understanding of code base
• Merging Engine updates was tedious
UE4: Extensibility APIs
• Modules, plug-ins, C++ interfaces
• Native code accessible to everyone
• Also supports non-programmers
How To Extend The Engine
General
Games
Editor
Plug-ins
Blueprint Construction Scripts
• Blueprints as macros to create & configure game objects
• Activated when an object is created in Editor or game
• Check out our excellent tutorials on YouTube!
How To Extend The Engine
General
Games
Editor
Plug-ins
Details View Customization
• Change the appearance of your types in the Details panel
• Customize per class, or per property
• Inject, modify, replace, or remove property entries
Menu Extenders
• Inject your own options into the Editor’s main menus
Tab Manager
• Register your own UI tabs
• Allows for adding entirely new tools and features
Default Appearance Detail Customizations
How To Extend The Engine
General
Games
Editor
Plug-ins
Blutilities
• Blueprints for the Editor!
• No C++ programming required
• Can fire off events that effect the Editor
• Currently experimental, but already working
• Scheduled for 4.5 (may change)
Procedural Textures, L-Systems, Flipbooks
How To Extend The Engine
General
Games
Editor
Plug-ins
Overview
• Extend the Engine, the Editor, or both
• Are completely self contained
• Can be enabled and disabled per project
• Everything should be a plug-in!
Examples
• BlankPlugin, UObjectPlugin – Use these to start coding
• Perforce & Subversion support for the Editor
• Oculus Rift support
• Movie players, Twitch Live Streaming, Slate Remote
• And many more!
How To Extend The Engine
General
Games
Editor
Plug-ins
All Plug-ins
• Will be loaded automatically on startup (if enabled)
• Most not be dependencies of the Engine or other plug-ins
Plug-ins with Code
• Have their own ‘Source’, ‘Binaries’, ‘Intermediates’ folders
• Can have one or more code modules
• May declare new UObject and UStruct types
• Seldom have Public header files in modules
Plug-ins with Content
• Have their own ‘Content’ folder
• Configuration files (INIs) not supported yet
How To Extend The Engine
General
Games
Editor
Plug-ins
Descriptor Files (.uplugin)
{
"FileVersion" : 3,
"FriendlyName" : "Paper2D",
"Version" : 1,
"VersionName" : "1.0",
"CreatedBy" : "Epic Games, Inc.",
"CreatedByURL" : "http://epicgames.com",
"EngineVersion" : "4.2.0",
"Description" : "Paper2D.",
"Category" : "2D.Helpers",
"EnabledByDefault" : true,
"Modules" :
[
// module definitions omitted
],
"CanContainContent" : true
}
Vertex Snapping, Ocean Surface, Rollercoaster
More on the Wiki!
Questions?
Documentation, Tutorials and Help at:
• AnswerHub:
• Engine Documentation:
• Official Forums:
• Community Wiki:
• YouTube Videos:
• Community IRC:
Unreal Engine 4 Roadmap• lmgtfy.com/?q=Unreal+engine+Trello+
http://answers.unrealengine.com
http://docs.unrealengine.com
http://forums.unrealengine.com
http://wiki.unrealengine.com
http://www.youtube.com/user/UnrealDevelopmentKit
#unrealengine on FreeNode
Concurrency & Parallelism
Synchronization Primitives
Atomics
Locking
Signaling
Waiting
FPlatformAtomics
• InterlockedAdd
• InterlockedCompareExchange (-Pointer)
• InterlockedDecrement (-Increment)
• InterlockedExchange (-Pointer)
64- and 128-bit overloads on supported platforms
Synchronization Primitives
Atomics
Locking
Signaling
Waiting
// Example
class FThreadSafeCounter
{
public:
int32 Add( int32 Amount )
{
return FPlatformAtomics::InterlockedAdd(&Counter, Amount);
}
private:
volatile int32 Counter;
};
Synchronization Primitives
Atomics
Locking
Signaling
Waiting
Critical Sections
• FCriticalSection implements synchronization object
• FScopeLock for scope level locking using a critical section
• Fast if the lock is not activated
Spin Locks
• FSpinLock can be locked and unlocked
• Sleeps or spins in a loop until unlocked
• Default sleep time is 0.1 seconds
Synchronization Primitives
Atomics
Locking
Signaling
Waiting
Semaphores
• Like mutex with signaling mechanism
• Only implemented for Windows and hardly used
• API will probably change
• Use FEvent instead
Synchronization Primitives
Atomics
Locking
Signaling
Waiting
FEvent
• Blocks a thread until triggered or timed out
• Frequently used to wake up worker threads
FScopedEvent
• Wraps an FEvent that blocks on scope exit
// Example for scoped events
{
FScopedEvent Event;
DoWorkOnAnotherThread(Event.Get());
// stalls here until other thread triggers Event
}
High Level Constructs
Containers
Helpers
General Thread-safety
• Most containers (TArray, TMap, etc.) are not thread-safe
• Use synchronization primitives in your own code where needed
TLockFreePointerList
• Lock free, stack based and ABA resistant
• Used by Task Graph system
TQueue
• Uses a linked list under the hood
• Lock and contention free for SPSC
• Lock free for MPSC
TDisruptor (currently not part of UE4)
• Lock free MPMC queue using a ring buffer
High Level Constructs
Containers
Helpers
FThreadSafeCounter
FThreadSingleton
• Singleton that creates an instance per thread
FMemStack
• Fast, temporary per-thread memory allocation
TLockFreeClassAllocator, TLockFreeFixedSizeAllocator
• Another fast allocator for instances of T
FThreadIdleStats
• Measures how often a thread is idle
Parallelization
Threads
Task Graph
Processes
Messaging
FRunnable
• Platform agnostic interface
• Implement Init(), Run(), Stop() and Exit() in your sub-class
• Launch with FRunnableThread::Create()
• FSingleThreadRunnable when multi-threading is disabled
FQueuedThreadPool
• Carried over from UE3 and still works the same way
• Global general purpose thread pool in GThreadPool
• Not lock free
Parallelization
Threads
Task Graph
Processes
Messaging
Game Thread
• All game code, Blueprints and UI
• UObjects are not thread-safe!
Render Thread
• Proxy objects for Materials, Primitives, etc.
Stats Thread
• Engine performance counters
Parallelization
Threads
Task Graph
Processes
Messaging
Task Based Multi-Threading
• Small units of work are pushed to available worker threads
• Tasks can have dependencies to each other
• Task Graph will figure out order of execution
Used by an increasing number of systems
• Animation evaluation
• Message dispatch and serialization in Messaging system
• Object reachability analysis in garbage collector
• Render commands in Rendering sub-system
• Various tasks in Physics sub-system
• Defer execution to a particular thread
Parallelization
Threads
Task Graph
Processes
Messaging
FPlatformProcess
• CreateProc() executes an external program
• LaunchURL() launches the default program for a URL
• IsProcRunning() checks whether a process is still running
• Plus many other utilities for process management
FMonitoredProcess
• Convenience class for launching and monitoring processes
• Event delegates for cancellation, completion and output
Parallelization
Threads
Task Graph
Processes
Messaging
Unreal Message Bus (UMB)
• Zero configuration intra- and inter-process communication
• Request-Reply and Publish-Subscribe patterns supported
• Messages are simple UStructs
Transport Plug-ins
• Seamlessly connect processes across machines
• Only implemented for UDP right now (prototype)
Upcoming Features
Critical sections & events
• Better debugging and profiling support
Task Graph
• Improvements and optimizations
UObjects
• Thread-safe construction and destruction
Parallel Rendering
• Implemented inside renderers, not on RHI API level
Messaging
• UDP v2 (“Hammer”), BLOB attachments, more robust, breakpoints
• Named Pipes and other transport plug-ins
More lock-free containers
Appendix A: Programming Tips
Getting Started
Tools:
• Windows: Visual Studio, UnrealVS, Visual Assist X (recommended)
• MacOS: XCode
For everything else see:
https://docs.unrealengine.com/latest/INT/Programming/QuickStart/
Common Blockers
Compiling
Acronyms
Entry Point
Compiling is handled through UBT
• UBT – Unreal Build Tool
• Solution/Projects in Visual Studio and Xcode are a lie!
Common Blockers
Compiling
Acronyms
Entry Point
Acronym Soup (and Code Names, too)
• UBT – Unreal Build Tool
• UHT – Unreal Header Tool
• UAT – Unreal Automation Tool
• UFE – Unreal Frontend
• BP – Blueprint
• CDO – Class Default Object
• INI – Text Based Configuration File
• Cooking – Optimizing game content
• Lightmass, Persona, Cascade, Swarm and other tools
• etc. pp.
Common Blockers
Compiling
Acronyms
Entry Point
I Want To Understand the Engine - Where Is the Main Loop?
• LaunchEngineLoop.cpp
• It’s really complicated (and everybody hates it)
• Please don’t bother with this – start with our tutorials!
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
We Use Prefixes for All Types
• U – UObject derrived class, i.e. UTexture
• A – AActor derrived class, i.e. AGameMode
• F – All other classes and structs, i.e. FName, FVector
• T – Template, i.e. TArray, TMap, TQueue
• I – Interface class, i.e. ITransaction
• E – Enumeration type, i.e. ESelectionMode
• b – Boolean value, i.e. bEnabled
Everything in Unreal is Pascal Case (Upper Camel Case)
• Function names and function parameters, too
• Even local and loop variables!
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
UObjects Work Around Limitations in C++
• Run-time reflection of class properties and functions
• Serialization from/to disk and over the network
• Garbage collection
• Meta data
• Also: Blueprint integration
Decorate regular C++ Classes with Magic Macros
• UCLASS – for class types
• USTRUCT – for struct types
• UFUNCTION – for class and struct member functions
• UPROPERTY – for class and struct variables
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
// Example (not actual UE4 code – omitting some more advanced details)
USTRUCT()
struct FVector2D
{
UPROPERTY()
float X;
UPROPERTY()
float Y;
UFUNCTION ()
float GetLength() const;
};
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
Fundamental Types
• We don’t use C++ integer types (char, short, int, long, etc.)
• Custom typedef’s for ints & strings in GenericPlatform.h
(int32, uint32, uint64, TCHAR, ANSICHAR etc.)
• Numeric type traits in NumericLimits.h
Common Structures
• FBox, FColor, FGuid, FVariant, FVector, TBigInt, TRange
• And many more in Core module
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
Containers
• TArray, TSparseArray – Dynamic arrays
• TLinkedList, TDoubleLinkedList
• TMap – Key-value hash table
• TQueue – Lock free FIFO
• TSet – Unordered set (without duplicates)
• And many more in Core module
Delegates
• Unicast and multicast delegates
• Also thread-safe variants
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
Smart Pointers
• TSharedPtr, TSharedRef – for regular C++ objects
• TWeakPtr – for regular C++ objects
• TWeakObjPtr – for UObjects
• TAutoPtr, TScopedPtr
• TUniquePtr
• Similar to boost:: & std:: implementations
• Also thread-safe variants
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
String Types
• FString – Regular string
• FText – Localized string, used heavily in Slate UI
• FName – String hash, used heavily in UObjects
String Literals
• TEXT() – Creates a regular(!) string, i.e. TEXT(“Hello”);
• LOCTEXT() – Creates a localized string, i.e.LOCTEXT(“Namespace”, “Name”, “Hello”);
• NSLOCTEXT() – LOCTEXT with scoped namespace, i.e.NSLOCTEXT(“Name”, “Hello”);
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
FNames are case-insensitive!
• Can’t rename ‘MisSpelled’ to ‘Misspelled’ in the Editor
• Can’t name a property ‘Blast’ if one ‘bLast’ exists
Unrealisms
Type Names
UObjects
Basic Types
Strings
Macros
Logging
• UE_LOG, also GLog->Logf()
Assertions
• check(), checkSlow(), ensure()
Localization
• LOCTEXT_NAMESPACE, LOCTEXT, etc.
Slate (UI Framework)
• SLATE_BEGIN_ARGS, SLATE_ATTRIBUTE, etc.
Best Practices
Guidelines
Principles
Coding Guidelines
• Posted on http://docs.unrealengine.com
• There are some inconsistencies in the code base
• If in doubt, follow existing style in current code file
Naming Conventions
• Choose descriptive names that are as short as possible
• Also for local and loop variables!
• Avoid your own acronyms
Best Practices
Guidelines
Principles
General Principles
• KISS, YAGNI
• Composition vs. inheritance
• Avoid tight coupling of code and modules
• Many trivial instead of few complicated components
Design Patterns
• SOLID (especially S, O, L and I; DI is not elegant in C++)
• Hollywood Principle (especially for Slate & game code)
• GOF, EIP
Methodologies
• DDD, TDD (we support unit tests), AOP
Appendix B: Build Automation
Build Tools
UHT
UBT
UAT
Unreal Header Tool (UHT)
• Written in C++
• Parses all C++ headers containing UClasses
• Generates glue code for all Unreal classes & functions
• Generated files stored in Intermediates directory
Build Tools
UHT
UBT
UAT
Unreal Build Tool (UBT)
• Written in C# (may convert to C++ in the future)
• Scans solution directory for modules and plug-ins
• Determines all modules that need to be rebuilt
• Invokes UHT to parse C++ headers
• Creates compiler & linker options from .Build.cs & .Target.cs
• Executes platform specific compilers (VisualStudio, LLVM)
Other UBT Features
• Project file generation (GenerateProjectFiles.bat)
• Remote Compilation (iOS, MacOS)
Build Rules
Dependency Graph
Build Tools
UHT
UBT
UAT
Unreal Automation Tool (UAT)
• Written in C# (may convert to C++ in the future)
• Automates repetitive tasks through Automation Scripts
• Build, cook, package, deploy and launch projects
• Invokes UBT for compilation
Other UAT Scripts
• Analyze and fix up game content files
• Code surgery when updating to new Engine versions
• Distributed compilation (XGE) & build system integration
• Generate code documentation
• Automated Testing of code and content
• And many others – you can add your own scripts!
UBT, UHT, UAT Projects
Build Automation
SCC
CIS
Promotion
Testing
Source Code Control (SCC)
• We use Perforce, but you don’t have to
• Not just code, but also content and everything else
• Also contains compiled binaries from build system (!)
• Used to version many other things (Markting, QA, etc.)
GitHub Integration
• Check-ins are pushed to GitHub Master in near real-time
• Script for converting GitHub pull requests to P4 CLs
Build Automation
SCC
CIS
Promotion
Testing
Continuous Integration System (CIS)
• Verifies all check-ins of code and content
• Grand Unified Build Process (GUBP)
• Thousands of build tasks a day
Backend Software
• Used custom build server for several years
• Experimented with Jenkins, but not scalable enough
• Now using Electric Commander
• Complex workflows with hundreds of jobs and sub-tasks
Build Hardware
• Virtualized farm of Windows and MacOS build servers
GUBP
Build Automation
SCC
CIS
Promotion
Testing
Build Promotion
• Selected successful CIS builds are tested by QA
• Builds that pass QA will be promoted to stable
• Selected stable builds become release candidates
• Approved stable builds are released to public
Build Automation
SCC
CIS
Promotion
Testing
UnrealSync
• Tool for artists to fetch the latest promoted build
• Aware of P4 branches and projects
• Notifies user when new promoted build is available
Build Automation
SCC
CIS
Promotion
Testing
Automated Testing
• Simple and complex tests
• Unit tests for C++, content verification
• Parallel testing on multiple platforms & devices
• Can also run from command line (as a Commandlet)
Simple Tests
• Single atomic test that can pass or fail
• Unit tests for C++, feature tests for content
• Examples: Play a map in PIE, verify text wrapping in Slate, etc.
Complex Tests
• Run same test code on a number of inputs
• Examples: Load all maps in the Editor, compile all Blueprints, etc.
// Example for a simple automation test that runs in a game
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FSetResTest, "Windows.SetResolution", ATF_Game)
bool FSetResTest::RunTest( const FString& Parameters )
{
FString MapName = TEXT("AutomationTest");
FEngineAutomationTestUtilities::LoadMap(MapName);
int32 ResX = GSystemSettings.ResX;
int32 ResY = GSystemSettings.ResY;
FString RestoreResolutionString = FString::Printf(TEXT("setres %dx%d"), ResX, ResY);
ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(2.0f));
ADD_LATENT_AUTOMATION_COMMAND(FExecStringLatentCommand(TEXT("setres 640x480")));
ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(2.0f));
ADD_LATENT_AUTOMATION_COMMAND(FExecStringLatentCommand(RestoreResolutionString));
return true;
}
Simple Automation Test
Automation Test Demo
Questions?
Documentation, Tutorials and Help at:
• AnswerHub:
• Engine Documentation:
• Official Forums:
• Community Wiki:
• YouTube Videos:
• Community IRC:
Unreal Engine 4 Roadmap• lmgtfy.com/?q=Unreal+engine+Trello+
http://answers.unrealengine.com
http://docs.unrealengine.com
http://forums.unrealengine.com
http://wiki.unrealengine.com
http://www.youtube.com/user/UnrealDevelopmentKit
#unrealengine on FreeNode