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

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.

主站蜘蛛池模板: 夹江县| 怀安县| 珲春市| 望江县| 海南省| 洪湖市| 阿勒泰市| 泸水县| 富宁县| 靖远县| 鲁山县| 峨边| 阿拉善右旗| 南开区| 达拉特旗| 武安市| 阳东县| 拉萨市| 永康市| 旌德县| 宁安市| 江城| 海南省| 濮阳市| 阜城县| 团风县| 巢湖市| 岳普湖县| 罗甸县| 湟中县| 迭部县| 清涧县| 石首市| 通渭县| 凤凰县| 阿鲁科尔沁旗| 柏乡县| 杭锦旗| 乌审旗| 墨江| 安阳县|