.obsidian
.vs
00-MOC
01-Diary
02-Note
03-UnrealEngine
Animation
Editor
Gameplay
AI
Animation
Code
Debug
GAS
Gameplay
Http
Lyra
Mass
Online
Other
PuerTS
UObject
UnrealSpecifiers
Flags
Meta
Specifier
UCLASS
UENUM
UFUNCTION
UINTERFACE
UPARAM
Blueprint
Const
DisplayName
Required
ref
Untitled.png
ref.md
Network
UPROPERTY
USTRUCT
UCLASS.md
UENUM.md
UFUNCTION.md
UINTERFACE.md
UPARAM.md
UPROPERTY.md
USTRUCT.md
UnrealSpecifiers.md
Ue4 c++ UProperty反射 PostEditChangeProperty.md
Ue4Object生命周期.jpg
大钊提供的一种获取UE Private函数的方法.md
LevelScene
Math
Mobile
Physical
Plugins
Rendering
Sequence
UI
VirtualProduction
VisualEffect
卡通渲染相关资料
性能优化
流程管理与部署
.keep
03-UnrealEngine.md
04-ComputerGraphics
05-SDHGame
06-DCC
07-Other
08-Assets
09-Templates
.gitattributes
.gitignore
.gitmodules
LICENSE
1.7 KiB
1.7 KiB
ref
-
功能描述: 使得函数的参数变成引用类型
-
元数据类型: bool
-
引擎模块: Blueprint, Parameter
-
作用机制: 在PropertyFlags中加入CPF_ReferenceParm
-
常用程度:★★★★★
普通参数和引用参数的区别是,在获取参数的时候,Ref类型会直接获得实参的引用,而不是拷贝。这样就可以避免拷贝,保存修改。
单纯的&参数是会被解析成输出返回参数,因此要用ref再继续标明。
测试代码:
//PropertyFlags: CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
UFUNCTION(BlueprintCallable)
FString MyFuncTestParam_Default(int& refValue);
//PropertyFlags: CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_ReferenceParm | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
UFUNCTION(BlueprintCallable)
FString MyFuncTestParam_Ref(UPARAM(ref) int& refValue);
UFUNCTION(BlueprintCallable)
FString MyFuncTestParam_Copy(int value);
蓝图的代码:
原理:
ref参数在UHT生成时会用P_GET_PROPERTY_REF来获得
#define P_GET_PROPERTY(PropertyType, ParamName) \
PropertyType::TCppType ParamName = PropertyType::GetDefaultPropertyValue(); \
Stack.StepCompiledIn<PropertyType>(&ParamName);
#define P_GET_PROPERTY_REF(PropertyType, ParamName) \
PropertyType::TCppType ParamName##Temp = PropertyType::GetDefaultPropertyValue(); \
PropertyType::TCppType& ParamName = Stack.StepCompiledInRef<PropertyType, PropertyType::TCppType>(&ParamName##Temp);