Unreal Engine中SetControlRotation调用报错C2660的原因咨询
Unreal Engine中SetControlRotation调用报错C2660的原因咨询
嘿,我来帮你拆解下这个报错的问题~
先看你贴的代码:
APlayerController* controller = UGameplayStatics::GetPlayerController(this->GetWorld(), 0); FRotator Rotation = Controller->GetControlRotation(); Controller->SetControlRotation(Rotation.Pitch + amount*5, Rotation.Yaw, Rotation.Roll);
你遇到的error C2660核心原因很明确:SetControlRotation函数的定义只接受一个FRotator类型的参数,但你现在直接传入了三个单独的浮点数(Pitch、Yaw、Roll的数值),这和函数要求的参数类型完全不匹配,所以编译器就抛出了“函数不接受3个参数”的错误。
另外还要提一句,你代码里的变量大小写不一致——前面定义的是小写的controller,后面调用时写成了大写的Controller,这在C++里是两个不同的变量,后续大概率还会触发未定义变量的错误,记得统一大小写哦。
正确的写法应该是先构造一个新的FRotator对象,把修改后的Pitch值和原有的Yaw、Roll组合进去,再传给函数:
APlayerController* controller = UGameplayStatics::GetPlayerController(this->GetWorld(), 0); if (controller) { // 加个空指针判断,避免空引用崩溃 FRotator Rotation = controller->GetControlRotation(); FRotator NewRotation = FRotator(Rotation.Pitch + amount*5, Rotation.Yaw, Rotation.Roll); controller->SetControlRotation(NewRotation); }
备注:内容来源于stack exchange,提问作者deado
相关产品推荐
相关产品推荐

