introduction to unreal engine

31
Introduction to Unreal Engine Jaanus Jaggo

Upload: others

Post on 18-Apr-2022

38 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Unreal Engine

Introduction to Unreal EngineJaanus Jaggo

Page 2: Introduction to Unreal Engine

Unreal EngineUnreal Engine is a powerful 3D game engine developed by Epic Games.

Unreal Engine 4 released to public in 2014.

Platforms: Windows, macOS, Linux, iOS, Android, Web

● primarily 3D● C++, Blueprints

Page 3: Introduction to Unreal Engine

History of Unreal Engine

1995 - Tim Sweeney (founder)started working on Engine for Unreal

2000 - Unreal Engine 2 2004 - Unreal Engine 3

2009 - Unreal Development Kit (UDK)Free version of UE3 available for general public

2014 Unreal Engine 42015 - no subscription (5% revenue share)

2020 - free until 1M$ revenue (after that 5% revenue share) Soon - Unreal Engine 5

Page 4: Introduction to Unreal Engine

C++ vs Blueprint Scripting

C++Pros:● Extreme performance● Source code access● Can do everything

Cons:● High complexity● Long compilation times● Easy to make mistakes

BlueprintsPros:● Easy to learn● Easy to prototype● Artist friendly● Harder to make crashing mistakes

Cons:● Slower performance● Some patterns are ugly (loops)● Can become messy● Less features

Page 5: Introduction to Unreal Engine

Architecture● Levels / Actors / Components● Blueprints● Game Mode / Game State / Game Instance● Player related classes● Accessing the main classes

Page 6: Introduction to Unreal Engine

Levels / Actors / ComponentsUnreal game is made of Levels, Actors and Components.

● Levels are similar to Scenes in Unity.● Actors are similar to GameObjects in Unity.● Components are similar to MonoBehaviours in Unity.

Every actor has a root component that can have an hierarchy of child components.

Unlike in Unity and Godot, the actors can’t be directly parented under each other but components can. There is a special component “child actor component” in case you need to parent actors under each other.

Page 7: Introduction to Unreal Engine

BlueprintsBlueprints are the script files that allow to define custom Actors and Components (and other things).

When making a blueprint you have to choose its parent class. This can be a C++ file or another blueprint.

These are the common parent classes

These are all the other classes that chosen

Page 8: Introduction to Unreal Engine

BlueprintsMain things that a blueprint has:

1. Component tree2. Event Graph with events3. Functions / Macros4. Variables5. Construction Script6. Class Settings / Class Defaults

Page 9: Introduction to Unreal Engine

Game Mode / Game State / Game InstanceMain configurations are in Edit → Project Settings → Maps & Modes

Game Mode: defines the rules of the game

● The number of players● How players spawn● Is the game paused● Transitions between levels

Game State: a public variable container for game mode

Game Instance: holds all presistent variables (data stored between levels)

Page 10: Introduction to Unreal Engine

Game ModeGame Mode defines the types of other main classes:

These are the most important ones for now

Page 11: Introduction to Unreal Engine

Player related classesPawn - Base class for any self moving actor (can be possessed)

Character - Pawn that can walk around

Player Controller - Responsible for sending player input to the possessed pawn. (Also responsible for the HUD)

Player Controller Character

Pawn

posesses

NB! In the First Person Template the input logic is FirstPersonCharacter class for simplicity. For a more complex game it should go to the PlayerController class.

Page 12: Introduction to Unreal Engine

Referencing main classesReferencing game related classes is simple, there are built in functions for each one of them:

You also need to cast them in case you created your own:

Referring to the player character should go through Player Controller.

In a single player game, the Player Index is always 0.

Page 13: Introduction to Unreal Engine

Blueprints Compendiumhttps://romeroblueprints.blogspot.com/p/table-of-contents.html

● Branch / Sequence / Switch● Loops● Variables● Events● Timers / Delays

Page 14: Introduction to Unreal Engine

Blueprint scriptingBranch Sequence

Switch

Page 15: Introduction to Unreal Engine

Blueprint scriptingForeach loop For loop

Page 16: Introduction to Unreal Engine

Blueprint scriptingVariables

Page 17: Introduction to Unreal Engine

Blueprint scriptingArrays

Page 18: Introduction to Unreal Engine

Blueprint scriptingEvents

Event dispatcher

Page 19: Introduction to Unreal Engine

Blueprint scriptingTimer Delay

Using timer handle:

Page 20: Introduction to Unreal Engine

Other things covered during labs● Enumerators● Data Tables● Interfaces● Functions / Macros● Construction Script● Level Blueprint

Page 21: Introduction to Unreal Engine

NetworkingUnreal engine features a robust networking framework.

All the previously studied components (GameMode, PlayerController, Character...) are made to work with multiplayer.

Unreal documentation suggests that “you should always program for multiplayer unless you are completely certain that your project will never need multiplayer features.”

Unreal Engine uses a client-server model. One computer acts as a server and hosts a sessions while other players’ computers connect as clients.

https://docs.unrealengine.com/en-US/Gameplay/Networking/Overview/index.html

Page 22: Introduction to Unreal Engine

NetworkingThe server, as the host of the game, holds the one true, authoritative game state.

The clients each remote-control Pawns, that they own on the server. They send procedure calls to them to perform in-game actions.

Server replicates information to each client, telling them what Actors should exist, how those Actors should behave, and what values different variables should have.

https://docs.unrealengine.com/en-US/Gameplay/Networking/Overview/index.html

Page 23: Introduction to Unreal Engine

Networking Modes and Server Types● Standalone - The game is running as a server that does not accept

connections from remote clients. It will run both server-side and client-side logic. (single-player and local multiplayer games)

● Client - The game is running as a client that is connected to a server. It will not run any server-side logic.

● Listen Server - The game is running as a server hosting a network multiplayer session. It accepts remote clients and has local players directly on the server. (casual cooperative and competitive multiplayer games)

● Dedicated Server - The game is running as a server hosting a network multiplayer session. It accepts remote connections but has no local player. It discards graphics, sounds, input etc. (secure or large-scale multiplayer games)

Page 24: Introduction to Unreal Engine

ReplicationReplication is the process of reproducing game state information between different machines in a network session.

By default most Actors do not have replication enabled and will perform all their functions locally. You can enable it by setting Replicates = true.

Page 25: Introduction to Unreal Engine

Replication

Replication Feature Description

Creation and Destruction When object is spawned / destroyed on server, it automatically gets spawned / destroyed on all clients.

Movement Replication When Actor has Replicate Movement enabled, it will replicate the Location, Rotation and Velocity.

Variable Replication Any value that is set to replicate will replicate whenever their value is changed.

Component Replication Actor components replicate as part of the Actor that owns them.

Remote Procedure Calls (RPCs) Special functions that are transmitted to specific machines in a network game.

Page 26: Introduction to Unreal Engine

OwnershipPawns in a network game are owned by a Player Controller.

Any time that Pawn calls a client-only funcion, it will be directed only to the owning player’s machine.

Actors that have their Owner set to a specific Pawn belong to that Pawn’s owning client. They will also direct client-only functions to their owner’s machine.

Use Is Locally Controlled to determine whether or not a Pawn is on its owning client.

Page 27: Introduction to Unreal Engine

Variable replicationTo replicate a variable you can either use:

● Replicated● RepNotify

RepNotify also creates a function that triggers locally when the variable is updated.

Page 28: Introduction to Unreal Engine

Remote Procedure Calls (RPC)They can be called from any machine but will direct their implementation to happen on a specific machine.

NB! Using variables and RepNotifies are preferable over using RPC’s whenever possible.

RPC Type Description

Server Called only on the server.

Client Called only on the client that owns the Actor where the function is.

NetMulticast Called on all clients that are connected to the server as well as the server itself.

Page 29: Introduction to Unreal Engine

Network CompendiumOne of the best source of information for developing multiplayer game in UE.

http://cedric-neukirchen.net/Downloads/Compendium/UE4_Network_Compendium_by_Cedric_eXi_Neukirchen.pdf

Page 30: Introduction to Unreal Engine

Main classes in replication

Page 31: Introduction to Unreal Engine

Main classes example