C++与蓝图互调

蓝图 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

原文链接: https://www.cnblogs.com/mattins/p/9234444.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++与蓝图互调

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/276690

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 上午1:56
下一篇 2023年2月15日 上午1:56

相关推荐