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
UnityGame 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
UnityBy 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
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
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
UnityBase 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 InputInput.GetAxis("MoveForward");
Input.GetTouch(0);Unreal Engine 4
Component UInputComponent of Actor classInputComponent->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)
UnityDebug.Log("Log text " + (0.1f).ToString());
Debug.LogWarning("Log warning");
Debug.LogError("Log error");Unreal Engine 4UE_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
| Unity3D | Unreal Engine 4 |
|---|---|
| int | int32, int24, int8 |
| string | FString |
| Transform | FTransform |
| Quaternion | FQuat |
| Rotation | FRotator |
| Gameobject | Actor |
| Array | TArray |
Member Functions and Variables
Most popular using function and variables| Unity3D | Unreal Engine4 |
|---|---|
| Update() | Tick() |
| transform | GetActorTranform(), GetFocalLocation() |
| transform.position | GetActorTranform().GetLocation() |
| transform.roation | GetActorTranform().GetRotation() |
| transform.localScale | GetActorTranform().GetScaled3D() |
| Destroy() | Destroy() |
| Find() | FActorIterator |
| MathF | FMath |
| RayCast | Trace |
| SphereCast | Sweep |
Components
| Unity3D | Unreal Engine4 |
|---|---|
| Transform | USceneComponent |
| Camera | UCameraComponent |
| BoxCollider | UBoxComponent |
| MeshFilter | UStaticMeshComponent |
| ParticleSystem | UParticleSystemComponent |
| AudioSource | UAudioComponent |
Related links
- Unreal Engine 4 overview. Features, cons and pros
- Unity Fog of War. Part 3. Static and dynamic fog of war
- Unity DLC system implementation tutorial
- Unity custom particle system video tutorial. Making Christmas tree and curves
- Unity fog of war tutorial. Part 1 (video tutorial)
- Project Anarchy vs Unity 3D. A comparison of two modern game engines
- Quaternions support in irrlicht engine
Author: Sergey Taraban