蓝图方法cpp使用
例:打LOG:Print String
蓝图节点的鼠标tips:Target is Kismet System Libraryphp
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h" UKismetSystemLibrary::PrintString(this, s) //KismetSystemLibrary 继承UObject
DEFINE_LOG_CATEGORY_STATIC(LogName, Log, All); //.cpp文件声明LOG。注:LogName不能重,Log是个枚举,All是个枚举 UE_LOG(LogName, Log, TEXT("abc %s"),s);//能够像Printf样打印出
DECLARE_LOG_CATEGORY_EXTERN(AAAAA, Log, All); //在.h文件声明LOG DEFINE_LOG_CATEGORY(AAAAA);//在.cpp文件使用
#include "Engine/Engine.h" GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s %f"), *Msg, Value));//引擎打LOG 注意-1 这个key能够用来当消息池索引
UFUNCTION(BlueprintCallable, Category = "test")
void SendMsg(FString msg);//供蓝图调用的C++函数c++
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "ReceiveEvent"))
void ReceiveEvent(const FString& message);//蓝图实现函数供C++调用函数
参考Actor BeginPlay:
meta=(DisplayName="BeginPlay")
void ReceiveBeginPlay
在C++ BeginPlay里调用ReceiveBeginPlaythis
UFUNCTION(BlueprintPure, Category = "TAMediator") //蓝图输出 绿色.net
UFUNCTION(BlueprintNativeEvent) //本函数可用C++或蓝图实现
void fun1();//蓝图覆写函数
virtual void fun1_Implementation();//UHT生成 c++要重写的函数debug
UINTERFACE(Category = "My Interface", BlueprintType, meta = (DisplayName = "My Interface")) class MYMODULE_API UMyInterface : public UInterface { GENERATED_UINTERFACE_BODY() }; class MYMODULE_API IMyInterface { GENERATED_IINTERFACE_BODY() public: UFUNCTION(BlueprintCallable) virtual void fun1();//Error UFUNCTION(BlueprintCallable) void fun1();//Error UFUNCTION(BlueprintNativeEvent) void fun1();//蓝图可覆写 /// My Initialization Interface. UFUNCTION(BlueprintNativeEvent, BlueprintCallable) void OnInitialized(const AMyActor* Context);// 蓝图可覆写可调用 UFUNCTION(BlueprintImplementableEvent) void Death();//True 在蓝图内以事件呈现 };
C++内调用 OnInitialized:code
const auto &Interface = Cast<IMyInterface>(Actor); if (Interface) { Interface->Execute_OnInitialized(Actor,Context); } // Else, Execute Interface on Blueprint layer instead: if (Actor->GetClass()->ImplementsInterface(UMyInterface::StaticClass())) { IMyInterface::Execute_OnInitialized(Actor,Context); }
https://wiki.unrealengine.com/index.php?title=Interfaces_in_C%2B%2B
https://blog.csdn.net/debugconsole/article/details/50454884blog