- Unreal Engine 4 Scripting with C++ Cookbook
- William Sherif Stephen Whittle
- 335字
- 2021-07-08 10:50:46
Chapter 2. Creating Classes
This chapter focuses on how to create C++ classes and structs that integrate well with the UE4 Blueprints editor. These classes are graduated versions of the regular C++ classes, and are called UCLASS
.
Tip
A UCLASS
is just a C++ class with a whole lot of UE4 macro decoration on top. The macros generate additional C++ header code that enables integration with the UE4 Editor itself.
Using UCLASS
is a great practice. The UCLASS
macro, if configured correctly, can possibly make your UCLASS
Blueprintable. The advantage of making your UCLASS
Blueprintable is that it can enable your custom C++ objects to have Blueprints visually editable properties (UPROPERTY
) with handy UI widgets such as text fields, sliders, and model selection boxes. You can also have functions (UFUNCTION
) that are callable from within a Blueprints diagram. Both of these are shown in the following screenshots:

On the left, two UPROPERTY
decorated class members (a UTexture
reference and an FColor
) show up for editing in a C++ class's Blueprint. On the right, a C++ function GetName
marked as BlueprintCallable
UFUNCTION
shows up as callable from a Blueprints diagram.
Note
Code generated by the UCLASS
macro will be located in a ClassName.generated.h
file, which will be the last #include
required in your UCLASS
header file, ClassName.h
.
The following are the topics that we will cover in this chapter:
- Making a
UCLASS
– deriving fromUObject
- Creating a user-editable
UPROPERTY
- Accessing a
UPROPERTY
from Blueprints - Specifying a
UCLASS
as the type of aUPROPERTY
- Creating a Blueprint from your custom
UCLASS
- Instantiating
UObject
-derived classes (ConstructObject <>
andNewObject <>
) - Destroying
UObject
-derived classes - Creating a
USTRUCT
- Creating a
UENUM()
- Creating a
UFUNCTION
Tip
You will notice that the sample objects we create in this class, even when Blueprintable, will not be placed in levels. That is because in order to be placed in levels, your C++ class must derive from the Actor
base class, or below it. See Chapter 4, Actors and Components for further details.
- Learn to Create WordPress Themes by Building 5 Projects
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- ASP.NET Core 5.0開發入門與實戰
- Java應用開發與實踐
- Visual Basic程序設計(第3版):學習指導與練習
- MATLAB應用與實驗教程
- Python程序設計案例教程
- Hands-On Automation Testing with Java for Beginners
- Hands-On Functional Programming with TypeScript
- R Deep Learning Cookbook
- 青少年信息學競賽
- Swift 4 Protocol-Oriented Programming(Third Edition)
- Python爬蟲、數據分析與可視化:工具詳解與案例實戰
- Arduino Wearable Projects
- C語言程序設計教程