Unreal Engine 5 C++ Project
✍ Last Updated : August 15, 2022
🚪 Prerequisites
Install Unreal Engine 5 and all of the prerequisites [Unreal Engine 5 Installation](Unreal Engine 5 Installation 3a14402970134e8689bdfce4fa8b4de5.md)
❓ Key Question / Problem / Issue
- How to create / start Unreal Engine 5 project with C++ as the base?
- How to create scripts which could control actor in a runtime?
✅ Expected Output/Definition of Done
- Unreal Engine 5 project with C++ as the base is created.
- C++ class scripts which have function to control / moving actor in a runtime.
🎁 Resulting Solution
Create C++ Project
-
Open/Launch Unreal Engine 5.
-
If there’s error on launching the apps, make sure you pass all of the engine requirement here Hardware and Software Specifications .
-
Once the Unreal Project Browser show up, at Games section, select one of game template or just select ‘Blank’.
-
At Project defaults, change to C++ as base project, let the rest default.
-
Fill up Project Name and click button Create.
-
Wait until the project open.
Open C++ Project
There’s two ways to open the project.
-
Open like usual from Unreal Project Browser:
-
Open from Visual Studio:
-
Open Visual Studio from project folder.
-
Set solution configuration to Development Editor
-
Run/Debug project with click F5 (Debugging) or Ctrl+F5 (Without Debugging), wait until Build succeeded and Unreal Engine Editor opened.
-
Create Custom Actor with C++ Script Component
-
Open Content Browser, at folder C++ Classes/[ProjectName].
-
Right click, and create New C++ Class..
-
Because we can make a script which can control object in scene, select Scene Component. Next
-
Fill up name, Create Class
-
After regenerating project files, its automatically open Visual Studio, with two script of our latest created C++ Class component
MoveComponents.cpp
(implementation) &MoveComponents.h
(header) opened. -
In
MoveComponents.h
add script to define parameter:private: // Parameter UPROPERTY(EditAnywhere) FVector MoveOffset; UPROPERTY(EditAnywhere) float Speed = 1.0f; UPROPERTY(EditAnywhere) bool MoveEnable = true; // Computed locations FVector StartRelativeLocation; FVector MoveOffsetNorm; float MaxDistance = 0.0f; float CurDistance = 0.0f; int MoveDirection = 1;
-
In
MoveComponents.cpp
, BeginPlay function. add script:
StartRelativeLocation = GetRelativeLocation();
// compute normalized movement
MoveOffsetNorm = MoveOffset;
MoveOffsetNorm.Normalize();
MaxDistance = MoveOffset.Length();
// check if ticking is required
SetComponentTickEnabled(MoveEnable);
-
In
MoveComponents.cpp
,Tick function. add script:// set the current distance if (MoveEnable) { CurDistance += DeltaTime * Speed * MoveDirection; if (CurDistance >= MaxDistance || CurDistance <= 0.0f) MoveDirection *= -1; } // compute and set current location SetRelativeLocation(StartRelativeLocation + MoveOffsetNorm * CurDistance);
-
Save file, and recompiles. Wait until compiling succeeded.
-
Create blueprint class, right click at Content Browser.
-
Select Actor, name it CustomChair, and open.
-
In Blueprint Editor, Add Component, Find MoveComponents. Add it.
-
Drag MoveComponents to DefaultSceneRoot, to make MoveComponents default.
-
Add StaticMesh component (follow step you add MoveComponent), and name it Chair.
-
Add models at Static Mesh details.
-
At MoveComponents fill Move Offset and speed. Compile and save blueprint.
-
Add CustomChair to Maps by drag it in. Play Level, the chair will move to offset with speed you fill.
Source
#01 - Creating A Project | UE5 C++ Tutorial
#02 - Actors & Components & Custom Move Component | UE5 C++ Tutorial
No Comments