Kismet庫
藍圖方法cpp使用
例:打LOG:Print String
藍圖節點的鼠標tips:Target is Kismet System Library
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"
UKismetSystemLibrary::PrintString(this, s) //KismetSystemLibrary 繼承UObject
C++打LOG
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可以用來當消息池索引
藍圖 C++ 互調
BlueprintCallable
UFUNCTION(BlueprintCallable, Category = "test")
void SendMsg(FString msg);//供藍圖調用的C++函數
BlueprintImplementableEvent
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "ReceiveEvent"))
void ReceiveEvent(const FString& message);//藍圖實現函數供C++調用
參考Actor BeginPlay:
meta=(DisplayName="BeginPlay")
void ReceiveBeginPlay
在C++ BeginPlay里調用ReceiveBeginPlay
BlueprintPure
UFUNCTION(BlueprintPure, Category = "TAMediator") //藍圖輸出 綠色
BlueprintNativeEvent
UFUNCTION(BlueprintNativeEvent) //本函數可用C++或藍圖實現
void fun1();//藍圖覆寫函數
virtual void fun1_Implementation();//UHT生成 c++要重寫的函數
C++實現藍圖接口
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:
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/50454884
