(UE4 4.20)UE4 UCLASS,UENUM, USTRUCT, UPROPERTY 的 常用配置
總結下我在專案中 “UCLASS,UENUM, USTRUCT, UPROPERTY”的常用配置, 持續更新
UCLASS
meta=(BlueprintSpawnableComponent)
讓一個ActorComponent變為藍圖可掛載元件
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT2_API UMyActorComponent : public UActorComponent
Blueprintable
讓一個UObject可以建立為藍圖BP類
UCLASS(Blueprintable)
class MYPROJECT2_API UTestObject : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
float a;
};
UENUM
作為C++列舉的巨集
UENUM()
enum class ECharactermMovementStatus : uint8
{
Run,
JUMP,
};
UCLASS(Blueprintable)
class MYPROJECT2_API UTestObject : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
float a;
UPROPERTY(EditAnywhere)
ECharactermMovementStatus CharactermMovementStatus;
};
USTRUCT
C++結構體的巨集
正常巢狀在UObject中藍圖化
USTRUCT()
struct FTest
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
float a;
UPROPERTY(EditAnywhere)
float b;
};
/**
*
*/
UCLASS(Blueprintable)
class MYPROJECT2_API UTestObject : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
FTest Test;
};
DataTable
做成CSV屬性配置表
#include "Engine/DataTable.h"
USTRUCT()
struct FTest : public FTableRowBase
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
float a;
UPROPERTY(EditAnywhere)
float b;
};
UPROPERTY
關於UPROPERTY的列舉都定義在ObjectMacros.h
namespace UP
{
// valid keywords for the UPROPERTY macro
enum
{
/// This property is const and should be exported as const.
Const,
/// Property should be loaded/saved to ini file as permanent profile.
Config,
/// Same as above but load config from base class, not subclass.
GlobalConfig,
/// Property should be loaded as localizable text. Implies ReadOnly.
Localized,
/// Property is transient: shouldn't be saved, zero-filled at load time.
Transient,
/// Property should always be reset to the default value during any type of duplication (copy/paste, binary duplication, etc.)
DuplicateTransient,
/// Property should always be reset to the default value unless it's being duplicated for a PIE session - deprecated, use NonPIEDuplicateTransient instead
NonPIETransient,
/// Property should always be reset to the default value unless it's being duplicated for a PIE session
NonPIEDuplicateTransient,
/// Value is copied out after function call. Only valid on function param declaration.
Ref,
/// Object property can be exported with it's owner.
Export,
/// Hide clear (and browse) button in the editor.
NoClear,
/// Indicates that elements of an array can be modified, but its size cannot be changed.
EditFixedSize,
/// Property is relevant to network replication.
Replicated,
/// Property is relevant to network replication. Notify actors when a property is replicated (usage: ReplicatedUsing=FunctionName).
ReplicatedUsing,
/// Skip replication (only for struct members and parameters in service request functions).
NotReplicated,
/// Interpolatable property for use with matinee. Always user-settable in the editor.
Interp,
/// Property isn't transacted.
NonTransactional,
/// Property is a component reference. Implies EditInline and Export.
Instanced,
/// MC Delegates only. Property should be exposed for assigning in blueprints.
BlueprintAssignable,
/// Specifies the category of the property. Usage: Category=CategoryName.
Category,
/// Properties appear visible by default in a details panel
SimpleDisplay,
/// Properties are in the advanced dropdown in a details panel
AdvancedDisplay,
/// Indicates that this property can be edited by property windows in the editor
EditAnywhere,
/// Indicates that this property can be edited by property windows, but only on instances, not on archetypes
EditInstanceOnly,
/// Indicates that this property can be edited by property windows, but only on archetypes
EditDefaultsOnly,
/// Indicates that this property is visible in property windows, but cannot be edited at all
VisibleAnywhere,
/// Indicates that this property is only visible in property windows for instances, not for archetypes, and cannot be edited
VisibleInstanceOnly,
/// Indicates that this property is only visible in property windows for archetypes, and cannot be edited
VisibleDefaultsOnly,
/// This property can be read by blueprints, but not modified.
BlueprintReadOnly,
/// This property has an accessor to return the value. Implies BlueprintReadOnly if BlueprintSetter or BlueprintReadWrite is not specified. (usage: BlueprintGetter=FunctionName).
BlueprintGetter,
/// This property can be read or written from a blueprint.
BlueprintReadWrite,
/// This property has an accessor to set the value. Implies BlueprintReadWrite. (usage: BlueprintSetter=FunctionName).
BlueprintSetter,
/// The AssetRegistrySearchable keyword indicates that this property and it's value will be automatically added
/// to the asset registry for any asset class instances containing this as a member variable. It is not legal
/// to use on struct properties or parameters.
AssetRegistrySearchable,
/// Property should be serialized for save game.
SaveGame,
/// MC Delegates only. Property should be exposed for calling in blueprint code
BlueprintCallable,
/// MC Delegates only. This delegate accepts (only in blueprint) only events with BlueprintAuthorityOnly.
BlueprintAuthorityOnly,
/// Property shouldn't be exported to text format (e.g. copy/paste)
TextExportTransient,
/// Property shouldn't be serialized, can still be exported to text
SkipSerialization,
};
}
這裡我主要講有關屬性反射到編輯器的,關於RPC在UPROPERTY的就不想講了, 那篇有關RPC的部落格就說過了。
EditAnywhere 與 Category
“EditAnywhere”可以任意在編輯器編輯值,Category 分類標籤
UPROPERTY(EditAnywhere, Category = "abc")
float a;
VisibleAnywhere
對於一般的 int, float, FString 等屬性在編輯器可見,但不能編輯
UPROPERTY(VisibleAnywhere, Category = "abc")
float a;
上面說“一般的” 是這樣,但是我發現在Actor建構函式中建立的ActorComponent元件的屬性想要編輯, 最好用VisibleAnywhere, 直接用EditAnywhere不是我們要的效果。
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* StaitcMeshComponent;
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
StaitcMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaitcMeshComponent"));
RootComponent = StaitcMeshComponent;
}
meta = (UIMin = "xxx1", UIMax = "xxx2")
實現把一個在編輯器的變數可編輯值從xxx1限制到xxx2, 如下所示:
UPROPERTY(EditAnywhere, Category = "abc", meta = (UIMin = "0.0", UIMax = "1.0"))
float a;
BlueprintReadOnly
變數在藍圖只讀
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "abc", meta = (UIMin = "0.0", UIMax = "1.0"))
float abc;
BlueprintReadWrite
變數在藍圖中能讀又能寫
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "abc", meta = (UIMin = "0.0", UIMax = "1.0"))
float abc;
參考資料
[1] https://docs.unrealengine.com/en-us/Programming/UnrealArchitecture/Reference/Properties/Specifiers
[3]https://docs.unrealengine.com/en-us/Programming/UnrealArchitecture/Reference/Metadata
相關文章
- (UE4 4.20 )UE4的GC(垃圾回收)程式設計規範GC程式設計
- (UE4 4.20)UE4 如何判斷一個點是否在導航網格(Navigation)內Navigation
- (UE4 4.20)UE4 繼承AnimNotify建立自定義動畫通知事件(結合PoseableMeshComponent實現技能殘影效果)繼承動畫事件
- UE4 智慧指標指標
- ue4打包遊戲遊戲
- UE4藍圖學習
- UE4 C++ 攀爬功能C++
- UE4 Dash功能實現
- UE4 c++ -- 簡單的UMGC++
- 《Inside UE4》開篇IDE
- UE4點選原始碼分析原始碼
- UE4網路模組解析(一)
- 《Inside UE4》目錄IDE
- Unreal Engine UE4開發技巧Unreal
- UE4 LoadMap 初始化
- ue4新增使用者介面、UIUI
- 《Inside UE4》基礎概念IDE
- Houdini在UE4特效中的嘗試分享特效
- UE4 ProjectileMovement Component 延遲啟動Project
- UE4中C++程式設計(一)C++程式設計
- UE4藍圖AI角色製作(三)AI
- 《Exploring in UE4》遊戲角色的移動原理(上)遊戲
- 《Exploring in UE4》遊戲角色的移動原理(下)遊戲
- UE4 UDP是如何進行可靠傳輸的UDP
- UE4 中射線檢測的簡單探索
- ue4為角色新增HP並繫結UIUI
- UE4 C++(11):移動元件和碰撞C++元件
- UE4中的位掩碼(Bitmask)的介紹和使用
- UE4 在當前遊戲模組新增一個新的模組遊戲
- UE4 Shader 編譯以及變種實現編譯
- 如何在UE4中實現植物風場效果?
- 《Exploring in UE4》移動元件詳解[原理分析]元件
- UE4 地形編輯-建立地形Landscape/terrainAI
- 雲渲染系統可多個UE4程式使用嗎?
- 如何在 UE4 移動端中實現 HZB?
- UE4純C++實現遊戲中快捷欄C++遊戲
- Aery的UE4 C++遊戲開發之旅(5)字元&字串C++遊戲開發字元字串
- UE4連結Android並呼叫解壓縮zip的介面Android