vault backup: 2024-10-12 17:19:45
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
# BlueprintInternalUseOnly
|
||||
|
||||
- **功能描述:** 不可定义新BP变量,但可作为别的类的成员变量暴露和变量传递
|
||||
- **元数据类型:** bool
|
||||
- **引擎模块:** Blueprint
|
||||
- **作用机制:** 在Meta中加入[BlueprintInternalUseOnly](../../../../Meta/Blueprint/BlueprintInternalUseOnly.md), [BlueprintType](../../../../Meta/Blueprint/BlueprintType.md)
|
||||
- **常用程度:** ★★
|
||||
|
||||
指明这个STRUCT会是个BlueprintType,但在蓝图编辑器中又不能声明新变量,但是可以作为别的类的成员变量暴露到蓝图中。
|
||||
|
||||
和不写BlueprintType的差别是什么?
|
||||
|
||||
不写BlueprintType则完全不能作为别的类的成员变量。BlueprintInternalUseOnly抑制了定义新变量的能力,但是可以作为变量传递。比如在C++中定义变量,然后在蓝图中传递。
|
||||
|
||||
如FTableRowBase本身并不能定义新变量,但是其子类(要加上BlueprintType)是可以定义新变量的,正常被使用。
|
||||
|
||||
## 示例代码:
|
||||
|
||||
```cpp
|
||||
//(BlueprintInternalUseOnly = true, BlueprintType = true, ModuleRelativePath = Struct/MyStruct_BlueprintInternalUseOnly.h)
|
||||
USTRUCT(BlueprintInternalUseOnly)
|
||||
struct INSIDER_API FMyStruct_BlueprintInternalUseOnly
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite,EditAnywhere)
|
||||
float Score=0.f;
|
||||
};
|
||||
|
||||
USTRUCT()
|
||||
struct INSIDER_API FMyStruct_NoBlueprintInternalUseOnly
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float Score=0.f;
|
||||
};
|
||||
|
||||
UCLASS(Blueprintable,BlueprintType)
|
||||
class INSIDER_API UMyClass_BlueprintInternalUseOnlyTest :public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY(BlueprintReadWrite,EditAnywhere)
|
||||
FMyStruct_BlueprintInternalUseOnly MyInternalStruct;
|
||||
|
||||
/*UPROPERTY(BlueprintReadWrite,EditAnywhere) //no supported by BP
|
||||
FMyStruct_NoBlueprintInternalUseOnly MyStruct;*/
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## 示例效果:
|
||||
|
||||
NewVar是UMyClass_BlueprintInternalUseOnlyTest 类型的,依然可以访问内部的MyInternalStruct变量。
|
||||
|
||||

|
||||
|
||||
源码里可以找到:
|
||||
|
||||
```cpp
|
||||
USTRUCT(BlueprintInternalUseOnly)
|
||||
struct FLatentActionInfo
|
||||
{}
|
||||
|
||||
USTRUCT(BlueprintInternalUseOnly)
|
||||
struct FTableRowBase
|
||||
{}
|
||||
```
|
||||
|
||||
## 原理:
|
||||
|
||||
```cpp
|
||||
bool UEdGraphSchema_K2::IsAllowableBlueprintVariableType(const UScriptStruct* InStruct, const bool bForInternalUse)
|
||||
{
|
||||
if (const UUserDefinedStruct* UDStruct = Cast<const UUserDefinedStruct>(InStruct))
|
||||
{
|
||||
if (EUserDefinedStructureStatus::UDSS_UpToDate != UDStruct->Status.GetValue())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// User-defined structs are always allowed as BP variable types.
|
||||
return true;
|
||||
}
|
||||
|
||||
// struct needs to be marked as BP type
|
||||
if (InStruct && InStruct->GetBoolMetaDataHierarchical(FBlueprintMetadata::MD_AllowableBlueprintVariableType))
|
||||
{
|
||||
// for internal use, all BP types are allowed
|
||||
if (bForInternalUse)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// for user-facing use case, only allow structs that don't have the internal-use-only tag
|
||||
// struct itself should not be tagged
|
||||
if (!InStruct->GetBoolMetaData(FBlueprintMetadata::MD_BlueprintInternalUseOnly))
|
||||
{
|
||||
// struct's base structs should not be tagged
|
||||
if (!InStruct->GetBoolMetaDataHierarchical(FBlueprintMetadata::MD_BlueprintInternalUseOnlyHierarchical))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Node->IsIntermediateNode()如果为true,则是作为中间节点使用,true会导致bForInternalUse为true
|
||||
if (!UK2Node_MakeStruct::CanBeMade(Node->StructType, Node->IsIntermediateNode()))
|
||||
```
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,67 @@
|
||||
# BlueprintInternalUseOnlyHierarchical
|
||||
|
||||
- **功能描述:** 在BlueprintInternalUseOnly的基础上,增加了子类也不能定义新BP变量的限制。
|
||||
- **元数据类型:** bool
|
||||
- **引擎模块:** Blueprint
|
||||
- **作用机制:** 在Meta中加入[BlueprintInternalUseOnlyHierarchical](../../../Meta/Blueprint/BlueprintInternalUseOnlyHierarchical.md)
|
||||
- **常用程度:★**
|
||||
|
||||
在BlueprintInternalUseOnly的基础上,增加了子类也不能定义新BP变量的限制。
|
||||
|
||||
目前只找到一个用处,但是也依然没有子类。如果我们在C++中定义新的子类,则所有的子类都不能定义变量。注意和FTableRowBase的区别是,FTableRowBase的子类依然可以定义新变量,因为FTableRowBase的BlueprintInternalUseOnly标记只作用于自己。
|
||||
|
||||
## 示例代码:
|
||||
|
||||
```cpp
|
||||
USTRUCT(BlueprintInternalUseOnlyHierarchical)
|
||||
struct GAMEPLAYABILITIESEDITOR_API FGameplayAbilityAuditRow : public FTableRowBase
|
||||
{}
|
||||
|
||||
USTRUCT(BlueprintInternalUseOnly)
|
||||
struct FTableRowBase
|
||||
{}
|
||||
```
|
||||
|
||||
## 原理:
|
||||
|
||||
只在这个地方用到,GetBoolMetaDataHierarchical会检查结构的所有父类测试是否含有某个标记。所以只要有一个父类有一个这个标记,就不能定义新变量。
|
||||
|
||||
```cpp
|
||||
bool UEdGraphSchema_K2::IsAllowableBlueprintVariableType(const UScriptStruct* InStruct, const bool bForInternalUse)
|
||||
{
|
||||
if (const UUserDefinedStruct* UDStruct = Cast<const UUserDefinedStruct>(InStruct))
|
||||
{
|
||||
if (EUserDefinedStructureStatus::UDSS_UpToDate != UDStruct->Status.GetValue())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// User-defined structs are always allowed as BP variable types.
|
||||
return true;
|
||||
}
|
||||
|
||||
// struct needs to be marked as BP type
|
||||
if (InStruct && InStruct->GetBoolMetaDataHierarchical(FBlueprintMetadata::MD_AllowableBlueprintVariableType))
|
||||
{
|
||||
// for internal use, all BP types are allowed
|
||||
if (bForInternalUse)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// for user-facing use case, only allow structs that don't have the internal-use-only tag
|
||||
// struct itself should not be tagged
|
||||
if (!InStruct->GetBoolMetaData(FBlueprintMetadata::MD_BlueprintInternalUseOnly))
|
||||
{
|
||||
// struct's base structs should not be tagged
|
||||
if (!InStruct->GetBoolMetaDataHierarchical(FBlueprintMetadata::MD_BlueprintInternalUseOnlyHierarchical))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
```
|
@@ -0,0 +1,35 @@
|
||||
# BlueprintType
|
||||
|
||||
- **功能描述:** 允许这个结构在蓝图中声明变量
|
||||
- **元数据类型:** bool
|
||||
- **引擎模块:** Blueprint
|
||||
- **作用机制:** 在Meta中加入[BlueprintType](../../../../Meta/Blueprint/BlueprintType.md)
|
||||
- **常用程度:★★★★★**
|
||||
|
||||
和UCLASS里的一样,可以允许这个结构在蓝图中声明变量
|
||||
|
||||
## 示例代码:
|
||||
|
||||
```cpp
|
||||
USTRUCT(BlueprintType)
|
||||
struct INSIDER_API FMyStruct_BlueprintType
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite,EditAnywhere)
|
||||
float Score;
|
||||
};
|
||||
|
||||
USTRUCT()
|
||||
struct INSIDER_API FMyStruct_NoBlueprintType
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float Score;
|
||||
};
|
||||
```
|
||||
|
||||
## 测试蓝图:
|
||||
|
||||

|
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
Reference in New Issue
Block a user