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

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
主站蜘蛛池模板: 曲靖市| 东海县| 冕宁县| 西青区| 天台县| 古交市| 陆丰市| 平凉市| 桓仁| 互助| 舞阳县| 齐河县| 淮滨县| 临江市| 多伦县| 左权县| 民和| 若羌县| 普兰县| 柘荣县| 大宁县| 建平县| 大同县| 江津市| 成武县| 农安县| 广东省| 祁东县| 江阴市| 改则县| 双峰县| 扎赉特旗| 加查县| 浦东新区| 满洲里市| 屯昌县| 博客| 永胜县| 中阳县| 沙洋县| 甘孜|