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

Accessing a UPROPERTY from Blueprints

Accessing a UPROPERTY from Blueprints is fairly simple. The member must be exposed as a UPROPERTY on the member variable that you want to access from your Blueprints diagram. You must qualify the UPROPERTY in your macro declaration as being either BlueprintReadOnly or BlueprintReadWrite to specify whether you want the variable to be either readable (only) from Blueprints, or even writeable from Blueprints.

You can also use the special value BlueprintDefaultsOnly to indicate that you only want the default value (before the game starts) to be editable from the Blueprints editor. BlueprintDefaultsOnly indicates the data member cannot be edited from Blueprints at runtime.

How to do it...

  1. Create some UObject-derivative class, specifying both Blueprintable and BlueprintType, such as the following:
    UCLASS( Blueprintable, BlueprintType )
    class CHAPTER2_API UUserProfile : public UObject
    {
      GENERATED_BODY()
      public:
      UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Stats)
      FString Name;
    };

    The BlueprintType declaration in the UCLASS macro is required to use the UCLASS as a type within a Blueprints diagram.

  2. Within the UE4 Editor, derive a Blueprint class from the C++ class, as shown in Creating a Blueprint from your custom UCLASS.
  3. Create an instance of your Blueprint-derived class in the UE4 Editor by dragging an instance from the Content Browser into the main game world area. It should appear as a round white sphere in the game world unless you've specified a model mesh for it.
  4. In a Blueprints diagram which allows function calls (such as the Level Blueprint, accessible via Blueprints | Open Level Blueprint), try printing the Name property of your Warrior instance, as seen in the following screenshot:

    Tip

    Navigating Blueprints diagrams is easy. Right-click and drag to pan a Blueprints diagram; Alt + Right-Click + Drag to zoom.

How it works…

UPROPERTY are automatically written Get/Set methods for UE4 classes. They must not be declared as private variables within the UCLASS, however. If they are not declared as public or protected members, you will get a compiler error of the form:

>> BlueprintReadWrite should not be used on private members
主站蜘蛛池模板: 通州区| 昌图县| 兴宁市| 工布江达县| 鲁甸县| 五指山市| 沙洋县| 南开区| 绍兴县| 崇仁县| 兴城市| 巫溪县| 招远市| 饶阳县| 保山市| 鹤庆县| 定边县| 明光市| 莆田市| 香格里拉县| 溧水县| 仁怀市| 房产| 武义县| 苍山县| 昭平县| 黎城县| 旌德县| 耒阳市| 勐海县| 黄陵县| 黔东| 洛川县| 南京市| 集安市| 缙云县| 武川县| 屏东县| 江华| 肃宁县| 南汇区|