Sitemap
Zac Bogner

Zac Bogner

Educator, Developer. Focused in Unreal Engine with other experience; Former Race Car Driver.

Intro to C++ in UE4 and UE5

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
Press enter or click to view image in full size
Press enter or click to view image in full size
  • 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.

Press enter or click to view image in full size
Press enter or click to view image in full size
  • 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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size
Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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

Get Zac Bogner’s stories in your inbox

Join Medium for free to get updates from this writer.

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

Press enter or click to view image in full size

Save and compile the code.

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

Press enter or click to view image in full size
Press enter or click to view image in full size

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
Press enter or click to view image in full size
Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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

Press enter or click to view image in full size

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

Press enter or click to view image in full size

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

--

--

Zac Bogner
Zac Bogner

Written by Zac Bogner

Educator, Developer. Focused in Unreal Engine with other experience; Former Race Car Driver.