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

Creating a Blueprint from your custom UCLASS

Blueprinting is just the process of deriving a Blueprint class for your C++ object. Creating Blueprint-derived classes from your UE4 objects allows you to edit the custom UPROPERTY visually inside the editor. This avoids hardcoding any resources into your C++ code. In addition, in order for your C++ class to be placeable within the level, it must be Blueprinted first. But this is only possible if the C++ class underlying the Blueprint is an Actor class-derivative.

Note

There is a way to load resources (such as textures) using FStringAssetReferences and StaticLoadObject. These pathways to loading resources (by hardcoding path strings into your C++ code) are generally discouraged, however. Providing an editable value in a UPROPERTY(), and loading from a proper concretely typed asset reference is a much better practice.

Getting ready

You need to have a constructed UCLASS that you'd like to derive a Blueprint class from (see the Making a UCLASS – deriving from UObject section earlier in this chapter) in order to follow this recipe. You must have also marked your UCLASS as Blueprintable in the UCLASS macro for Blueprinting to be possible inside the engine.

Tip

Any UObject-derived class with the meta keyword Blueprintable in the UCLASS macro declaration will be Blueprintable.

How to do it…

  1. To Blueprint your UserProfile class, first ensure that UCLASS has the Blueprintable tag in the UCLASS macro. This should look as follows:
    UCLASS( Blueprintable )
    class CHAPTER2_API UUserProfile : public UObject
  2. Compile and run your code.
  3. Find the UserProfile C++ class in the Class Viewer (Window | Developer Tools | Class Viewer). Since the previously created UCLASS does not derive from Actor, to find your custom UCLASS, you must turn off Filters | Actors Only in the Class Viewer (which is checked by default):

    Turn off the Actors Only check mark to display all the classes in the Class Viewer. If you don't do this, then your custom C++ class may not show!

    Tip

    Keep in mind that you can use the small search box inside the Class Viewer to easily find the UserProfile class by starting to type it in:

  4. Find your UserProfile class in the Class Viewer, right-click on it, and create a Blueprint from it by selecting Create Blueprint…
  5. Name your Blueprint. Some prefer to prefix the Blueprint class name with BP_. You may choose to follow this convention or not, just be sure to be consistent.
  6. Double-click on your new Blueprint as it appears in the Content Browser, and take a look at it. You will be able to edit the Name and Email fields for each UserProfile Blueprint instance you create.

How it works…

Any C++ class you create that has the Blueprintable tag in its UCLASS macro can be Blueprinted within the UE4 editor. A Blueprint allows you to customize properties on the C++ class in the visual GUI interface of UE4.

主站蜘蛛池模板: 宁陕县| 德兴市| 吕梁市| 常熟市| 东莞市| 博乐市| 奈曼旗| 阿尔山市| 淮安市| 桑植县| 夏河县| 陇川县| 双桥区| 玉山县| 五台县| 平塘县| 辽阳县| 苍梧县| 历史| 潮州市| 罗甸县| 大同市| 安远县| 育儿| 抚宁县| 绩溪县| 德格县| 剑河县| 十堰市| 从江县| 定西市| 和顺县| 泰来县| 修武县| 桑植县| 钟祥市| 当雄县| 刚察县| 长顺县| 罗山县| 通化市|