官术网_书友最值得收藏!

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 from UObject
  • Creating a user-editable UPROPERTY
  • Accessing a UPROPERTY from Blueprints
  • Specifying a UCLASS as the type of a UPROPERTY
  • Creating a Blueprint from your custom UCLASS
  • Instantiating UObject-derived classes (ConstructObject <> and NewObject <>)
  • 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.

主站蜘蛛池模板: 澳门| 延津县| 北辰区| 蒲江县| 施甸县| 青川县| 绥江县| 临高县| 湄潭县| 永和县| 景泰县| 绵阳市| 昆山市| 东乌珠穆沁旗| 漯河市| 突泉县| 大同县| 彭山县| 靖宇县| 永川市| 太谷县| 宁明县| 永寿县| 沙湾县| 灌南县| 长寿区| 宕昌县| 阿鲁科尔沁旗| 临沂市| 临夏县| 历史| 吉水县| 新宁县| 灵山县| 内黄县| 梁河县| 瓮安县| 彰化市| 安国市| 兴隆县| 三明市|