**
一、蓝图调用.cpp函数
**
.h文件
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UFUNCTION(BlueprintCallable, Category = "MyOpenDoor")//被蓝图调用的特性 ,可以在蓝图函数列表中搜索到
void TestFuncFromCPlusPlus();
.cpp文件
void UOpenDoor::TestFuncFromCPlusPlus()
{
UE_LOG(LogTemp, Warning, TEXT("TestFuncFromC++!"));
}
二、.cpp函数调用蓝图
1.把.h文件中的UCLASS设置为蓝图可以调用, 添加Blueprintable。
UCLASS(Blueprintable, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
2.把c++类转为蓝图
**a.通过c++脚本创建蓝图。
蓝图如下:
b.之后把蓝图挂载在场景中的物体上。**
3.在.h文件中添加
#include "Misc/OutputDeviceDebug.h"//引用输出设备Debug的源文件库
4.在.cpp文件中
// Called when the game starts
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
FString cmd = FString::Printf(TEXT("TestFuncFromBP ABCDEF"));
FOutputDeviceDebug device;
//CallFunctionByNameWithArguments通过参数名回调函数
CallFunctionByNameWithArguments(*cmd,device,NULL,true);
}