UE4/5c++如何创建有多个输出变量(引脚)的函数

​@[toc]

普通函数:

一般制作一个函数只需要这样:

比如我想要做一个计算向量内的值然后输出为浮点的纯函数,并且想要蓝图可用:

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "calculate")
float calculateVallAbsAddFloat(FVector a);

然后实现即可
​​请添加图片描述
但是这只能输出一个浮点数,而不能输出多个浮点数。

多个输出的函数:

那么面对这种情况,如果我想要的是输入一个向量输出多个浮点应该怎么做?

答案很简单,众所周知c++里面void的函数是没有返回值的,同样也只是进行更改,但是在ue里面不同,我们想要输出多个引脚的值,那么void是最好的办法:

那么要如何制作?

首先是要输入的值,以const 类型& 来进行表示

而想要输出的值则是以类型&来进行表示

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "calculate")
void VclampFtoVB(const FVector& a, float& F, float& B, float& L, float& R);

这样我就制作了一个可以输出多个浮点型引脚的纯函数,当然其他的函数也是可以的。

而我们只需要在cpp文件中做好对要输出的用&的值进行赋予即可。
请添加图片描述

多个输入的函数也是一样:

只需要添加多个const 类型& 即可

扫描二维码关注公众号,回复: 14588556 查看本文章
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "calculate")
void abccc(const FVector& a, const FVector& b, const FVector& c, FVector& L, float& R);

结果:
在这里插入图片描述

当然void并不是必须的

如果我想一定要float放在前面,习惯改不掉也没关系:

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "calculate")
float abccc(const FVector& a, const FVector& b, const FVector& c, FVector& L, float& R);

情况就是这样:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/q244645787/article/details/128754389