Unreal Engine 4 key concepts of C++ programming and comparison with Unity

In this article I will briefly describe a basics concepts of the developing using Unreal Engine 4 and compare it with Unity developing. It will help you to fast understand how Unreal Engine 4 works especially if you are Unity programmer. This article is based on UE4 guide for Unity developers and contained additional information

Author: Sergey Taraban

:ad:

Key concepts

Game logic

Unity

Game logic is writing using Mono environment. Scripts manipulate the objects. Object can have a lot of scripts or does not have any. Every script are equal.

Minimal application does not have any scripts or objects (empty scene). Programmer should creates objects with scripts which realize required game logic

Unreal Engine 4

Game logic are writing using C++ and/or Blueprint Editor. C++ class and blueprint manipulates the objects. Object can have only one class and blueprint connected to this class.

Minimal application has stiff architecture which consist of several main classes were wrote on C++, which realize multilayer FPS game logic. Programmer in common case should derives from this class for realize required game logic.

Game start

Unity

By default level with index 0 is loaded. After this Awake function of script, which object were spawned first, is called, or if this script has highest priority (Script Execution Order).

Unreal Engine 4

Level setted by default (Edit > Project Settings > Maps & Modes ) is loaded. Every level has settings WorldSettings class. using this class  UWorld class are created. UWorld creates object of class GameMode in scene. GameMode object creates PlayerController object and other object.

Program enter point is constructor of the class inherited from GameMode.

Scene

Concept of the Scene in both engines is the same. Unity3D and UE4 have different axes definitions.

Unity

Y axis up.

  • X - left, right
  • Y - up, down
  • Z - forwards, backwards
File format: *.scene

Use GameObject static methods for scene objects operations ( find, spawn, destroy)

Level loading: Application.LoadLevel(string name);

Unreal Engine4

Z axis up.

  • X - forwards, backwards
  • Y - left, right
  • Z - up, down
File format: *.umap

Use UWorld class method for scene objects operations ( find, spawn, destroy). You can get UWorld using GetWorld() method of class PlayerController.

Level loading: GetWorld()->ServerTravel(string URL);

URL - path to the level. Can include additional parameters. Example:

/Game/Maps/<map_name>?<key_1>=<value_1>&<key_2>=<value_2>

Reading parameters in code (GameMode class) GetIntOption(OptionsString, <key_1>, <default_value>);

Scene objects

Unity

Base scene object - GameObject.

GameObjects are containers for all other Components. Has Transform component by default. Components are then added to give the GameObject functionality. GameObject cannot has components with the same type (except scripts). Components not support parent-child relation.

You can combine several Game Objects in group and link to root Game Object (parent-child relation).

Unreal Engine 4

Base scene object  - Actor.

An Actor is the base object that can be placed or spawned into the world. An Actor by itself does not even contain a Transform component. The Actor is simply the base object which can have a presence in the level. Components are the independent objects. It is like a GameObject in Unity. One Actor can has a lot of components of one type. Most of components support parent-child relation (but not all).

Programmer can inheriting from default components and creates his own.

Component spawn example:

TSubobjectPtr SceneComponent = PCIP.CreateDefaultSubobject(this, TEXT("SceneComp"));
RootComponent = SceneComponent;

Input events

Unity Class Input
Input.GetAxis("MoveForward");
Input.GetTouch(0);
Unreal Engine 4 Component UInputComponent of Actor class
InputComponent->BindAxis("MoveForward", this, &AFirstPersonBaseCodeCharacter::MoveForward);
InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &AStrategyPlayerController::OnTapPressedMy);
...
void AStrategyPlayerController::OnTapPressedMy(ETouchIndex::Type index, FVector ScreenPosition)
{
}

Print to console (log)

Unity
Debug.Log("Log text " + (0.1f).ToString());
Debug.LogWarning("Log warning");
Debug.LogError("Log error");
Unreal Engine 4
UE_LOG(LogTemp, Log, TEXT("Log text %f"), 0.1f);
UE_LOG(LogTemp, Warning, TEXT("Log warning"));
UE_LOG(LogTemp, Error, TEXT("Log error"));
FError::Throwf(TEXT("Log error"));
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(TEXT("Dialog message")));

Main classes and function

Base data types

Unity3DUnreal Engine 4
intint32, int24, int8
stringFString
TransformFTransform
QuaternionFQuat
RotationFRotator
GameobjectActor
ArrayTArray

Member Functions and Variables

Most popular using function and variables
Unity3DUnreal Engine4
Update()Tick()
transformGetActorTranform(), GetFocalLocation()
transform.positionGetActorTranform().GetLocation()
transform.roationGetActorTranform().GetRotation()
transform.localScaleGetActorTranform().GetScaled3D()
Destroy()Destroy()
Find()FActorIterator ActorItr(GetWorld()),ConstructorHelpers::FObjectFinder object(name)
MathFFMath
RayCastTrace
SphereCastSweep

Components

Unity3DUnreal Engine4
TransformUSceneComponent
CameraUCameraComponent
BoxColliderUBoxComponent
MeshFilterUStaticMeshComponent
ParticleSystemUParticleSystemComponent
AudioSourceUAudioComponent
 

Related links

Author: Sergey Taraban