Intro to C++ in UE4 and UE5

Zac Bogner
4 min readApr 7, 2024

This article will cover some basics of C++ with Unreal Engine 4 and 5.

UE4 C++ and Interface:

What I will cover in this article:

  • Intro to C++ Classes
  • Creating an Actor Class
  • Creating a Static Mesh Component

What is a C++ Class?

C++ Classes are data structures that hold information, storing data types to declare functions and variables within the object oriented programming (OOP) code base.

  • Creating an Actor C++ Class
  • CPP and Header Files

The CPP file is used to call the functions and variables listed in the Header file. A CPP file contains the code block of the program to execute within the application once the code is compiled.

  • The Header file is a list of member variables and data structures that can be declared with the base class using public, private, and protected member functions to display the properties associated within the CPP file.
  • Creating a C++ Static Mesh Component

To have visible property associates within the UI, we need to declare the UPROPERTY class specifier.

The UPROPERTY can be linked to Blueprints where we can directly modify properties listed.

To be able to modify our UPROPERTY contents, we need to set the visibility to VisibleAnywhere.

  • VisibleAnywhere — Indicates that this property is visible in all property windows, but cannot be edited. This Specifier is incompatible with the “Edit” Specifiers.

Next, we create the Static Mesh Component (UStaticMeshComponent) and get reference by using a pointer operator to declare the name.

Now we can save and compile the code (at the top of the toolbar) to view the C++ class in the viewport of our C++ Project Folder.

When we drag in the Actor to the scene, we can see in the Details Panel My Test Actor is created and My Static Mesh is successfully generated.

To assign our Static Mesh Component in the details panel, we need to Create our Static Mesh Component.

Pass in our static mesh variable > Create a default sub object (include Static Mesh Component class) and add a text for the name.

Save and compile the code.

Now we have the ability to assign a static mesh of any kind.

UE5 C++ and Interface:

When upgrading engine versions, some features get moved around and syntax also gets changed in code.

Some new features in UE5 from UE4 include:

  • Darker themed UI
  • Default scene with Landscape
  • Content Drawer on Bottom
  • Compile Code and Live Coding Button on Lower Right Corner
  • Simpler Toolbar on Upper Left Corner

With the new Live Coding feature in UE5, sometimes the classes folder doesn’t show up, so toggling on and off the live coding compiler settings can help rebuild the project files to display in the content browser.

The below code block, I use the EditAnywhere property specifier. EditAnywhere property can be edited by property windows, on archetypes and instances. This Specifier is incompatible with any of the the “Visible” Specifiers.

Additionally, we can shorthand the text field without including the TEXT property, to just get the string name we want for the Static Mesh Component.

Now we save and compile code, and can assign the static mesh we want.

And now we have created an Static Mesh Actor class that we can use to populate our scene.

Next, we will look into creating a Mesh from File Actor.

--

--

Zac Bogner

Game Designer and Level Designer, formerly with Rainbow Studios. Focused in Unreal Engine with experience in Unity. Former Race Car Driver.