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

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
主站蜘蛛池模板: 济南市| 麟游县| 丰台区| 乳山市| 容城县| 安龙县| 托克托县| 纳雍县| 武强县| 涿州市| 东明县| 南皮县| 班玛县| 太和县| 中山市| 庄浪县| 花莲县| 吴忠市| 墨江| 东阳市| 盘山县| 茌平县| 张家港市| 湖州市| 石城县| 合肥市| 奉新县| 樟树市| 孟村| 大邑县| 钟山县| 微山县| 和平县| 湘乡市| 邢台县| 大邑县| 牙克石市| 嘉义市| 湘潭县| 安泽县| 鹤峰县|