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

Creating a UFUNCTION

UFUNCTION() are useful because they are C++ functions that can be called from both your C++ client code as well as Blueprints diagrams. Any C++ function can be marked as a UFUNCTION().

How to do it...

  1. Construct a UClass with a member function that you'd like to expose to Blueprints. Decorate that member function with UFUNCTION( BlueprintCallable, Category=SomeCategory) to make it callable from Blueprints. For example, the following is the Warrior class again:
    // Warrior.h
    class WRYV_API AWarrior : public AActor
    {
      GENERATED_BODY()
      public:
      UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Properties)
      FString Name;
      UFUNCTION(BlueprintCallable, Category = Properties)
      FString ToString();
    };
    
    // Warrior.cpp
    FString UProfile::ToString()
    {
      return FString::Printf( "An instance of UProfile: %s", *Name );
    }
  2. Create an instance of your Warrior class by dragging an instance on to your game world.
  3. From Blueprints, call the ToString() function on that Warrior instance by clicking on your Warrior instance. Then, in a Blueprints diagram, type in ToString(). It should look like in the following screenshot:

Tip

In order to call a function on an instance, the instance must be selected in the World Outliner when you start to type into the autocomplete menu in the Blueprints diagram, as shown in the following screenshot:

How it works…

UFUNCTION() are really C++ functions, but with additional metadata that make them accessible to Blueprints.

主站蜘蛛池模板: 绥滨县| 满洲里市| 襄城县| 朝阳县| 乌兰县| 泰州市| 宁阳县| 上蔡县| 林芝县| 勐海县| 松桃| 夏邑县| 高台县| 凤阳县| 新竹县| 兴城市| 阿尔山市| 萨嘎县| 彭阳县| 游戏| 县级市| 筠连县| 益阳市| 仁怀市| 宣威市| 丰原市| 马尔康县| 大余县| 定远县| 社旗县| 梁平县| 友谊县| 信阳市| 通州市| 台东县| 澄迈县| 游戏| 资兴市| 乌什县| 上林县| 康平县|