Files
.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
UPROPERTY
Asset
Blueprint
BlueprintAssignable
BlueprintAuthorityOnly
BlueprintCallable
BlueprintGetter
BlueprintGetter.md
Untitled.png
BlueprintReadOnly
BlueprintReadWrite
Setter
BlueprintSetter.md
Getter.md
Config
DetaisPanel
Instance
Network
Serialization
UHT
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

42 lines
2.0 KiB
Markdown
Raw Normal View History

2024-10-12 17:19:46 +08:00
# BlueprintGetter
- **功能描述:** 为属性定义一个自定义的Get函数来读取。
- **元数据类型:** string="abc"
- **引擎模块:** Blueprint
- **作用机制:** 在PropertyFlags中加入[CPF_BlueprintReadOnly](../../../../Flags/EPropertyFlags/CPF_BlueprintReadOnly.md)、[CPF_BlueprintVisible](../../../../Flags/EPropertyFlags/CPF_BlueprintVisible.md)在Meta中加入[BlueprintGetter](../../../../Meta/Blueprint/BlueprintGetter.md)
- **常用程度:** ★★★
为属性定义一个自定义的Get函数来读取。
如果没有设置BlueprintSetter或BlueprintReadWrite则会默认设置BlueprintReadOnly这个属性变成只读的。
## 示例代码:
```cpp
public:
//(BlueprintGetter = , Category = Blueprint, ModuleRelativePath = Property/MyProperty_Test.h)
UFUNCTION(BlueprintGetter, Category = Blueprint) //or BlueprintPure
int32 MyInt_Getter()const { return MyInt_WithGetter * 2; }
//(BlueprintSetter = , Category = Blueprint, ModuleRelativePath = Property/MyProperty_Test.h)
UFUNCTION(BlueprintSetter, Category = Blueprint) //or BlueprintCallable
void MyInt_Setter(int NewValue) { MyInt_WithSetter = NewValue / 4; }
private:
//(BlueprintGetter = MyInt_Getter, Category = Blueprint, ModuleRelativePath = Property/MyProperty_Test.h)
//PropertyFlags: CPF_BlueprintVisible | CPF_BlueprintReadOnly | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPrivate
UPROPERTY(BlueprintGetter = MyInt_Getter, Category = Blueprint)
int32 MyInt_WithGetter = 123;
//(BlueprintSetter = MyInt_Setter, Category = Blueprint, ModuleRelativePath = Property/MyProperty_Test.h)
//PropertyFlags: CPF_BlueprintVisible | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPrivate
UPROPERTY(BlueprintSetter = MyInt_Setter, Category = Blueprint)
int32 MyInt_WithSetter = 123;
```
## 示例效果:
可见MyInt_WithGetter是只读的。
而MyInt_WithSetter 是可读写的。
![Untitled](Untitled.png)