// .h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "FuncLibTest.generated.h"
/**
*
*/
UCLASS()
class UECPP_API UFuncLibTest : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "MyTest")
static void TestPrint(); // 注意这里不写static在蓝图中使用就要多连一个self
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "FuncLibTest.h"
void UFuncLibTest::TestPrint()
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 9.f, FColor::Red, TEXT("Debug"));
}
}
同理,添加对应的函数参数和返回值。会体现在蓝图参数中
FName不区分大小写,用于快速定位资源是否相同,所以内部维护了哈希值
FText比较重,描述文本,可以用于多语言
FString最接近 std::string
转换规则
FName,FText可以通过 ToString()转FString
FString=>FName 通过FName构造函数丢入一个FString实例FName var = FName(*FStringIns)
FString=>FText通过 FText::FromString()
FName=>FText
FText::FromName()
TEXT宏主要是为了不乱码。ASCII到 TCHAR
创建Actor的cpp类,然后创建对应蓝图脚本。添加注解可被蓝图使用
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "UI")
float TestFloat;
UFUNCTION(BlueprintCallable, Category = "UI")
void TestFunc();
如下,函数不用实现,在蓝图中实现函数体。Cpp中调用这个函数相当于触发了蓝图的这个Event。实现cpp中调用蓝图逻辑
UFUNCTION(BlueprintImplementableEvent)
void TestEvent();
UFUNCTION(BlueprintNativeEvent)
void TestNativeEvent();
注意其在对应cpp的实例函数比较特殊
void ATestActor::TestNativeEvent_Implementation()
{
}
UFUNCTION(BlueprintPure, Category = "UI", meta = (NativeBreakFunc))
void BreakFunc(const FRandomStream &MyRendom, bool isV);
UFUNCTION(BlueprintPure, meta = (DisplayName = "HelloW", CompactNodeTitle = "Hello", Keywords = "Hello", CommutativeAssociativeBinaryOperator = "true"), Category = "UI")
float MyHello(float a, float b);
void ATestActor::BreakFunc(const FRandomStream &MyRendom, bool isV)
{
}
float ATestActor::MyHello(float a, float b)
{
return a > b ? a : b;
}
UFUNCTION(BlueprintPure, meta = (Z = "1", NativeMakeFunc), Category = "UI") // Z 是初始值
FVector TestMakeVector(float x, float y, float z);
FVector ATestActor::TestMakeVector(float x, float y, float z)
{
FVector v;
v.X = x;
v.Y = y;
v.Z = z;
return v;
}
UENUM()
namespace MyType
{
enum Type
{
Type_1,
Type_2,
};
}
UPROPERTY(EditAnywhere, Category = "UI")
TEnumAsByte<MyType::Type> Var;
原文:https://www.cnblogs.com/Q1143316492/p/14401102.html