I’m listening to you guys. You wanted some C++ tutorials so here we go. I will do more C++ stuff later.

Next step with the project is to add level selection screen. I will create base data classes in C++.

<strong>This Tutorial has been created using Unreal Engine 4.9.2</strong> Make sure you are working on the same version of the engine. 1 2 < strong > This Tutorial has been created using Unreal Engine 4.9.2 < / strong > Make sure you are working on the same version of the engine .

Design

There will be three levels in the game which:

will have different difficulty,

will have different type of enemies,

take some time to complete,

level icon reference,

level background reference,

All of those will be visible in level selection screen (which I don’t have yet ) so I will create structure and enums inside C++ for later use.

“I can’t code!”

I have the same problem so don’t be afraid to install Visual Studio and try using C++. Why you should use C++? Main arguments for me:

Storing variables and declaring structures / enums in C++ is stable, you won’t get issues that can come when using Blueprints. Another thing is that your blueprints will load faster. I suggest to store variables / structures / enums inside C++ and I will work this way from Today.,

Placing math to C++ will increase your game performance,

And last one – most important: if you know how to blueprint you can learn C++ to create variables and math functions without a problem. It will be hard from start to understand UE4 macros but you should try.

How to Learn?

This book can help you a lot, Read this wiki page, Learn basics of C++, Learn by watching Epics code! This is the way I’m using. If I want to create blueprint pure function I’m searching one that was created earlier by Epic and trying to copy it with my variables / references. Watch all Youtube “UE4 C++ Tutorial” especially from Epic.

Enabling C++ creation

If you want to use C++ in your project simply add blank code to project. It will ask you to download Visual Studio – just do the whole steps. Restart your computer and again add code to project. Then restart your editor.

Adding Enums

If you don’t know how to open Visual Studio use FILE -> OPEN VISUAL STUDIO from Editor.

Navigate your project .h file. I have named my project “ShooterTutorial” so it’s ShooterTutorial.h file.

You can add Enums in every class. I’m using project .h file because it sounds like it’s global.

To add new Enum type add these to your project .h file: (PasteBin)

// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "Engine.h" #include "ShooterTutorial.generated.h" // //without this you will get compile error after GENERATED_USTRUCT_BODY() - always add .generated.h UENUM(BlueprintType) //"BlueprintType" is essential to include so you can create this enum in Blueprints. enum class ELevelEnemyType : uint8 // Name of Enum. Need starts with 'E'. This enum will hold type of enemies inside the level. Just as information in level selection screen. { ET_Robots UMETA(DisplayName = "Robots"), ET_Humans UMETA(DisplayName = "Humans"), ET_Aliens UMETA(DisplayName = "Aliens") }; UENUM(BlueprintType) //"BlueprintType" is essential to include so you can create this enum in Blueprints. enum class ELevelDifficulty : uint8 // This enum will hold level difficulty displayed in level selection screen. { LD_Easy UMETA(DisplayName = "Easy"), LD_Medium UMETA(DisplayName = "Medium"), LD_Hard UMETA(DisplayName = "Hard") }; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "Engine.h" #include "ShooterTutorial.generated.h" // //without this you will get compile error after GENERATED_USTRUCT_BODY() - always add .generated.h UENUM ( BlueprintType ) //"BlueprintType" is essential to include so you can create this enum in Blueprints. enum class ELevelEnemyType : uint8 // Name of Enum. Need starts with 'E'. This enum will hold type of enemies inside the level. Just as information in level selection screen. { ET_Robots UMETA ( DisplayName = "Robots" ) , ET_Humans UMETA ( DisplayName = "Humans" ) , ET_Aliens UMETA ( DisplayName = "Aliens" ) } ; UENUM ( BlueprintType ) //"BlueprintType" is essential to include so you can create this enum in Blueprints. enum class ELevelDifficulty : uint8 // This enum will hold level difficulty displayed in level selection screen. { LD_Easy UMETA ( DisplayName = "Easy" ) , LD_Medium UMETA ( DisplayName = "Medium" ) , LD_Hard UMETA ( DisplayName = "Hard" ) } ;

Please read comments inside the code for explanation. Now if you compile your project you can create new Enums in Blueprints from LevelEnemyType and LevelDifficulty.

Adding Structures

Here’s great Tutorial about structures in c++. And here’s my code – just copy it after enums declarations. (PasteBin)

USTRUCT(BlueprintType) //again BlueprintType means you can use this structure in Blueprints. struct FLevelData //name of structure - need start with 'F' this structure will hold level data which will be displayed in level selection screen. { GENERATED_USTRUCT_BODY() // without this you will get compile errors UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") // this means you can break structure in blueprints + it will be replicated. //Always use UPROPERTY() macro in variables. ELevelEnemyType EnemiesType; // declaring ELevelEnemy Enum in ELevelData structure. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") ELevelDifficulty LevelDifficulty; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") float LevelTime; // levels will be time based that's why we need to declare how long we can play before end of the level. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") float HiScore; // we will store HiScore in this structure so it can be seen in level selection screen. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") UObject* SequenceData; // reference to Object which will store sequence of enemies for the level. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") UMaterial* LevelIcon; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") UMaterial* LevelBackground; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Data") FString LevelToLoad; //name of the level to load. //Constructor FLevelData() { //Always initialize your USTRUCT variables! // exception is if you know the variable type has its own default constructor EnemiesType = ELevelEnemyType::ET_Robots; LevelDifficulty = ELevelDifficulty::LD_Easy; LevelTime = 120.0f; HiScore = 0.0f; SequenceData = NULL; //means clear reference } }; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 USTRUCT ( BlueprintType ) //again BlueprintType means you can use this structure in Blueprints. struct FLevelData //name of structure - need start with 'F' this structure will hold level data which will be displayed in level selection screen. { GENERATED_USTRUCT_BODY ( ) // without this you will get compile errors UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) // this means you can break structure in blueprints + it will be replicated. //Always use UPROPERTY() macro in variables. ELevelEnemyType EnemiesType ; // declaring ELevelEnemy Enum in ELevelData structure. UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) ELevelDifficulty LevelDifficulty ; UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) float LevelTime ; // levels will be time based that's why we need to declare how long we can play before end of the level. UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) float HiScore ; // we will store HiScore in this structure so it can be seen in level selection screen. UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) UObject * SequenceData ; // reference to Object which will store sequence of enemies for the level. UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) UMaterial * LevelIcon ; UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) UMaterial * LevelBackground ; UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = "Level Data" ) FString LevelToLoad ; //name of the level to load. //Constructor FLevelData ( ) { //Always initialize your USTRUCT variables! // exception is if you know the variable type has its own default constructor EnemiesType = ELevelEnemyType :: ET_Robots ; LevelDifficulty = ELevelDifficulty :: LD_Easy ; LevelTime = 120.0f ; HiScore = 0.0f ; SequenceData = NULL ; //means clear reference } } ;

Please read the comments for explanation. After compiling you can create new variable of LevelData structure type! It’s so simple!

I would need to move ShooterTutorial blog to custom server to get the code highlights…for now please use PasteBin links. Here you can find whole code for enums and structures. Remember that my project name is ShooterTutorial – your will be different!