Unreal Engine 4 C++ Let's Start
Unreal Engine is Great, Robust Programming, Node Programming (Blueprint), and High Quality Graphics Game Development Engine. Unreal Engine is Free for everyone this is the big Positive options with game developers.
Unreal Engine uses Blueprint and C++ Programming language for Game-play Programming.
Why C++
In Unreal engine C++ not hard but not simple or another this is using great rules of Programming like we macros for variables declarations or define Functions or UENUM etc.
Unreal Engine uses it's own many features to make C++ easy for every one;
C++ and Blueprint
Unreal Engine uses C++ Programming and Blueprint Visual Scripting for non- programmers or designers(we made full game with Blueprints).
Key Features:
- Blueprint create new game-play elements Using C++, programmers add the base game-play systems that designers or non-programmers use the create own custom game-play for a level or for the game.
- C++ : Programmers works in IDE Microsoft Visual Studio 2019 (Preview);
- Game Play Classes and Framework classes access both of systems;
- True power of these programmers make C++ blocks and designers make block and make interesting game play;
- Simply Programmers that creating C++ block for the Designers.
We going on whole Basics
Class
check Out this blog Post (Recommended)
https://mahadakashdev.blogspot.com/2018/03/unreal-engine-418-c-lets-started_45.html
We Do Some Basics
Deep To C++ of UEngine
We now looking useful objects and some features they provided by Unreal Engine.
Game Class: Objects, Actors, Components
Four Main class Types
They are UObject, AActor, UActorComponent and UStruct.
Unreal Objects (UObjects)
UObjects : base building block coupled with UClass.
Provide Services :
- Reflection of properties and methods
- Serialization of properties
- Garbage collection
- Finding UObjects by name
- Configurable values for properties
- Networking support for properties and methods
Each Class derives from UObject has a singleton UClass for it that contains of the meta data about the class instance;
Root of everything : UObject and UClass
UClass And UObject Difference :
UClass describe what an instance of a UObject will look like
UObject what properties are available for serialization, networking etc. Mostly Gameplay development instead from AActor and UActorComponent but not from deriving UObjects.
We need this information but is good for these systems exist;
AActor
AActor == UObject that mean be part of the gameplay experience.
Actors : placed in level by a designer or created at run time by gameplay systems;
All objects that will placed in Level they extend from this class
Simply : we placed actors or objects in Game play world they all used Actor class or Object;
Ex : AStaticMeshActor, ACameraActor and APointLight etc;
AActors can destroyed through C++ or Blueprint ;
AActors Unloaded from memory when the uses Standard garbage collection mechanism;
AActors are responsible for the high-level behaviors of your game's objects. AActors type that replicated during networking. During Networking replication. AActor distribute information for any UActorComponent that own and that require network support or synchronization.
Actors have events that are called during lifecycle
BeginPlay
: Called when the Actor first comes into existence during gameplay.Tick
: Called once per frame to do work over time.EndPlay
: Called when the object is leaving the gameplay space.
UActorComponent
Actor Components : own behaviors and are usually responsible for functionality that is shared across many types of Actors:
Ex: Providing Visual meshes, particle effects, camera perspectives and physics interactions.
Components attach with other components. can be the root component of an Actor;
Components attach only with parent Component of or Actor but if you have child Components attached itself;
RootComponent
- this is the member ofAActor
that holds the top level Component in the Actor's tree of Components- Ticking - Components are ticked as part of the owning Actor's
Tick
function. (Be sure to callSuper::Tick
when writing your ownTick
function.)
How to work with Components Check Out
https://mahadakashdev.blogspot.com/2018/03/unreal-engine-c-programming-static-mesh_87.html
UStruct
UStruct : use USTRUCT(); and UE4 build tools will do the base work for you;
UStructs : Not Garbage Collected. if you create dynamic instance you can manage life-cycle yourself.
Still More!!
Engine Working Systems;
Unreal Reflection System
Reflection : Ability of a program to examine itself at run-time;
Very useful and foundation technology of the Unreal Engine, Powering many systems such as details panel in the Editor, serialization, garbage collection, network replication, and Blueprint/C++ communication
How is ?
C++ does not native support any form of reflection. So Unreal Engine has its own to Harvest query, and enumerations.
The reflection system is opt-in.
You need to annotate any type of properties that you want to be visible to reflection system, and UNREAL HEADER TOOL (UHT) will harvest that information when you compile your project.
To Mark a header as containing reflected types, add special include at the top of the file.
That Unreal Engine know or consider this file and this requires for implementation of the system.
in Header file we see always a filename.genrated.h
#include "Filename.generated.h"
We now use UENUM(), UCLASS(), UFUNCTION() and UPROERTY() to annotate different types and member variables in the header.
All members declarations and contains additional specifier keyword.
#pragma once #include “CoreMinimal.h” #include “GameFramework/Actor.h” #include “AChreter.generated.h” // This file UHT UCLASS() class CPLUSTHIREDBOOKNEW_API AAChreter : public AActor { GENERATED_BODY() public: // Sets default values for this actor’s properties AAChreter(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; public: // Called every frame virtual void Tick(float DeltaTime) override; // Check out Variables UPROPERTY(EditAnywhere) USceneComponent * Root; UPROPERTY(EditAnywhere) UStaticMeshComponent * Mesh; };
It uses UCLASS() that indicates it is reflected, with a macro GENERATED_UCLASS_BODY()
inside of the definition.
GENERATED_UCLASS_BODY()
and GENERATED_USTRUCT_BODY()
macros are require in reflected classes and macros.
- UCLASS() - Used to tell Unreal to generate reflection data for a class. The class must derive from UObject.
- USTRUCT() - Used to tell Unreal to generate reflection data for a struct.
- GENERATED_BODY() - UE4 replaces this with all the necessary boilerplate code that gets generated for the type.
- UPROPERTY() - Enables a member variable of a UCLASS or a USTRUCT to be used as a UPROPERTY. A UPROPERTY has many uses. It can allow the variable to be replicated, serialized, and accessed from Blueprints. They are also used by the garbage collector to keep track of how many references there are to a UObject.
- UFUNCTION() - Enables a class method of a UCLASS or a USTRUCT to be used as a UFUNCTION. A UFUNCTION can allow the class method to be called from Blueprints and used as RPCs, among other things.
official Links of Specifies check out
Object/Actor Iterators
Object Iterators is useful tool to iterate over all instances of a particular UObject type and its SubClasses;
// Will find ALL current UObject instances for (TObjectIteratorIt; It; ++It) { UObject* CurrentObject = *It; UE_LOG(LogTemp, Log, TEXT("Found UObject named: %s"), *CurrentObject->GetName()); } Ex > from Unreal Engine Docs
Actor iterators work in much the same way as object iterators, but only work for objects that derive from AActor
APlayerController* MyPC = GetMyPlayerControllerFromSomewhere(); UWorld* World = MyPC->GetWorld(); // Like object iterators, you can provide a specific class to get only objects that are // or derive from that class for (TActorIteratorIt(World); It; ++It) { // ... } Ex > from Unreal Engine Docs
Creating an Actor iterator, you need to give it a pointer to a UWorld instace.
Memory Management and Garbage Collection
UObjects and Garbage Collection
UE4 uses reflection system to implement garbage collection system.You will not manually manage garbage collection your UObject, you just need to maintain valid references to them.
Your classes need to derive from UObject in order to be enabled for garbage collection.
Actors and Garbage Collection
Actors not usually garbage collection aside from during level's shutdown.
Once the actor spawned you need to manually call destroy on them to remove them from without level ending.They will not be deleted immediately instead will be cleaned up during the next garbage collection phase
Class Naming Prefixes
A > Actor ex: AController;
U > Object ex: UComponent;
Enums > E ex:ETypename;
Inerface > I ex: IAbilitySystemInterface;
Template > T ex: TArray;
Classes that derive from SWidget (Slate UI) > S ex: SButton;
Everything else is prefixed by the F ex: FColour , FVector etc;
Numeric Types
Different Platform have different sizes for basic such as short, int, and long
int8/uint8 : 8-bit signed/unsigned integer;
- int16/uint16 : 16-bit signed/unsigned integer
- int32/uint32 : 32-bit signed/unsigned integer
- int64/uint64 : 64-bit signed/unsigned integer
floating points numbers are also supported with the standard float (32-bit) and double (64-bit) types;
Strings
FString
FString mutable string, analogous to std::string;
FString large suit of methods for making it easy to work with strings;
FString MyStr = TEXT("Hello, Unreal 4!").
FText
It is meant for localized text. NSLOCTEXT() This macro takes a namespace, key, and a value for the default language
FText MyText = NSLOCTEXT("Game UI", "Health Warning Message", "Low Health!")
FName
FName stores commonly recurring strings as an identifiers in order to save memory and CPU time when comparing them.
TCHAR are used as a way of stroing characters independent of the character set being used, which may differ between platform.
Containers
Primary function is to store collections of data. the most of these classes are TArray, TMap and TSet.
Comments
Post a Comment