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

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.

主站蜘蛛池模板: 托里县| 得荣县| 蓝田县| 新宁县| 孟村| 乳源| 南平市| 沙坪坝区| 万年县| 冕宁县| 迁西县| 张家界市| 措勤县| 丰城市| 汤阴县| 房产| 彭州市| 奉贤区| 洱源县| 山丹县| 台前县| 淳化县| 西平县| 凤翔县| 马龙县| 娱乐| 汶上县| 兴义市| 达尔| 台南市| 阿克| 定襄县| 长治市| 昌黎县| 喀什市| 财经| 乐亭县| 乌拉特后旗| 木兰县| 延津县| 罗平县|