OnComponentBeginOverlap.AddDynamic 的编译错误【UE4】
发布日期:2021-07-01 05:53:44
浏览次数:2
分类:技术文章
本文共 1735 字,大约阅读时间需要 5 分钟。
以 Character 类为例,假设有 PacManCharacter 派生自 Character类 首先在 PacManCharacter.h 头文件中添加碰撞函数的声明:
OnCollision 为自定义的碰撞函数,名称可以任意,但参数形式必须满足以下条件
UFUNCTION()void OnCollision(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
然后在 PacManCharacter.cpp 文件中的 SetupPlayerInputComponent 函数中添加绑定函数:
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &PacManCharacter::OnCollision);
碰撞函数的实现:
void PacManCharacter::OnCollision(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult){ GEngine->AddOnScreenDebugMessage(0, 1.0f, FColor::Red, TEXT("PacMan ! "));}
但是以上是老版本的 UE4 支持的格式,编译会报参数类型不匹配的错误
error C2664: 'void TBaseDynamicMulticastDelegate::__Internal_AddDynamic(UserClass *,void (__cdecl AItem::* )(UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &),FName)': cannot convert argument 2 from 'void (__cdecl AItem::* )(AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &)' to 'void (__cdecl AItem::* )(UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &)'
新版本的 UE4 应该对碰撞函数进行如下声明和定义:
UFUNCTION()void OnCollision(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
void PacManCharacter::OnCollision(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult){ GEngine->AddOnScreenDebugMessage(0, 1.0f, FColor::Red, TEXT("PacMan ! "));}
即增加了第一个参数 class UPrimitiveComponent* HitComp
转载地址:https://panda1234lee.blog.csdn.net/article/details/60584606 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年05月07日 03时40分41秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
有了这些 Chrome 插件,效率提升10倍(建议收藏)
2019-05-01
一名 Google 工程师的大数据处理经验
2019-05-01
命名难,难于上青天
2019-05-01
没钱没公司,怎么做一款付费产品
2019-05-01
代码整洁之道-编写 Pythonic 代码
2019-05-01
树莓派程序开机自启动
2019-05-01
连锁门店无线通信方案
2019-05-01
配置Lotus Domino集群视频详解
2019-05-01
Linux软件万花筒
2019-05-01
全球开源软件发展趋势分析
2019-05-01
python 多进程之进程池的操作
2019-05-01
flask整理之 flask程序中的debug模式
2019-05-01
比特币,父母这一辈能接受吗?
2019-05-01
首个聚合器怎么产生的,并运用领域在什么
2019-05-01
区块链技术应用,最先医疗行业
2019-05-01
《增长黑客》(肖恩·艾利斯)学习笔记——第二部分 实战
2019-05-01
python使用HTMLTestRunner查看运行函数
2019-05-01
linux下安装jenkins+git+python
2019-05-01
解决uiautomatorviewer中添加xpath的方法
2019-05-01