UE4函数标记BlueprintImplementableEvent和BlueprintNativeEvent区别

/// This function is designed to be overridden by a blueprint.  Do not provide a body for this function;
        /// the autogenerated code will include a thunk that calls ProcessEvent to execute the overridden body.
        BlueprintImplementableEvent,

        /// This function is designed to be overridden by a blueprint, but also has a native implementation.
        /// Provide a body named [FunctionName]_Implementation instead of [FunctionName]; the autogenerated
        /// code will include a thunk that calls the implementation method when necessary.
        BlueprintNativeEvent,
 

BlueprintImplementableEvent:在C++可以声明函数(不能定义,蓝图重写),在C++里调用该函数,蓝图重写实现该函数

BlueprintNativeEvent:在C++可以声明和定义函数,在C++里调用该函数,蓝图重写实现该函数(蓝图可以重写或不重写C++父类函数)

MyTPCharacter.h

函数声明(BlueprintImplementableEvent和BlueprintNativeEvent):


	UFUNCTION(BlueprintImplementableEvent)
		void TestA();

	UFUNCTION(BlueprintImplementableEvent)
		int TestB();

	UFUNCTION(BlueprintImplementableEvent)
		void TestC(const FString& str);

	UFUNCTION(BlueprintImplementableEvent)
		int TestD(const FString& str);

	UFUNCTION(BlueprintNativeEvent)
		void TestE();

	UFUNCTION(BlueprintNativeEvent)
		int TestF();

	UFUNCTION(BlueprintNativeEvent)
		void TestG(const FString& str);

	UFUNCTION(BlueprintNativeEvent)
		int TestH(const FString& str);

MyTPCharacter.cpp

函数定义(BlueprintImplementableEvent不能定义和BlueprintNativeEvent定义):

BlueprintNativeEvent修饰函数定义格式:函数名_Implementation

void AMyTPCharacter::TestE_Implementation()
{
	PrintScreenStr("TestE_Implementation");
}
int AMyTPCharacter::TestF_Implementation()
{
	PrintScreenStr("TestF_Implementation");
	return 1;

}
void AMyTPCharacter::TestG_Implementation(const FString& str)
{
	PrintScreenStr("TestG_Implementation " + str);
	
}
int AMyTPCharacter::TestH_Implementation(const FString& str)
{
	PrintScreenStr("TestH_Implementation " + str);
	return 1;
}

C++调用这些函数:

void AMyTPCharacter::OnRunEvent()
{

	 TestA();
	 TestB();
	 TestC("TestC");
	 TestD("TestC");
	 TestE();
	 TestF();
	 TestG("TestG");
	 TestH("TestH");

}

蓝图可以重写函数:如下图,选中重写实现

 

BlueprintImplementableEvent和BlueprintNativeEvent修饰函数,有返回值和没有返回值区别,如下

BlueprintImplementableEvent和BlueprintNativeEvent修饰函数,是否重写C++父类函数,如下

运行效果:

总结:BlueprintNativeEvent和BlueprintImplementableEvent修饰函数,如果没有函数返回值,那就是类似蓝图事件通知,如果有函数返回值,那就是类似蓝图函数重写;都可以传参和返回值;BlueprintNativeEvent修饰函数在C++有声明和定义实现,在蓝图可以覆写该函数,蓝图是否调用C++定义父类函数;BlueprintNativeEvent修饰函数只有声明,没有定义实现,只能在蓝图重写实现;BlueprintNativeEvent和BlueprintImplementableEvent修饰函数都只能在C++其他函数里调用。

  • 17
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值