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

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.

主站蜘蛛池模板: 吉林省| 老河口市| 潢川县| 白银市| 武宁县| 桐庐县| 曲阳县| 广南县| 泰顺县| 遵化市| 宁陵县| 巴彦淖尔市| 孟连| 金秀| 泸定县| 宁安市| 治多县| 深泽县| 运城市| 关岭| 绩溪县| 平潭县| 芜湖县| 勃利县| 时尚| 广灵县| 镇巴县| 和静县| 上饶县| 龙游县| 南汇区| 饶阳县| 喀什市| 芮城县| 波密县| 湘阴县| 松原市| 石泉县| 吉水县| 新安县| 通州市|