[UE4] Enumeration type output

This article uses the output method of record enumeration type of UE4.26

1. Definition and use of enumeration types

  In UE, designing an enumeration type can be done in the following ways (see details \Engine\Source\Runtime\Engine\Classes\Engine\Blueprint.h):

/** Type of compilation. */
namespace EKismetCompileType
{
    
    
	enum Type
	{
    
    
		SkeletonOnly,
		Full,
		StubAfterFailure, 
		BytecodeOnly,
		Cpp,
	};
};

/** Compile modes. */
UENUM()
enum class EBlueprintCompileMode : uint8
{
    
    
	Default UMETA(DisplayName="Use Default", ToolTip="Use the default setting."),
	Development UMETA(ToolTip="Always compile in development mode (even when cooking)."),
	FinalRelease UMETA(ToolTip="Always compile in final release mode.")
};

  The first one uses a namespace, and its variables are defined in the following way:

/** The compile type to perform (full compile, skeleton pass only, etc) */
EKismetCompileType::Type 	CompileType;

  How to use:

if (CompileOptions.CompileType == EKismetCompileType::Full)
{
    
    
	// ...
}

  The second method does not use namespaces, and the variable definition method is:

/** The mode that will be used when compiling this class. */
UPROPERTY(EditAnywhere, Category=ClassOptions, AdvancedDisplay)
EBlueprintCompileMode CompileMode;

  How to use:

if (OwningBP->CompileMode != EBlueprintCompileMode::Default))
{
    
    
	// ...
}

  There is little difference between the two methods, and the output method is also the same, divided into two types: 1. Output integer type, 2. Output string.

2. Enumeration type output

2.1 Integer output

  The enumeration type itself is integer data, so it can be output directly as an integer:

UE_LOG(LogTemp, Error, TEXT("Current is %d"), EBlueprintCompileMode::Development);

  can get the outputLogTemp: Error: Current is 1

2.2 String output

  When there are many enumeration types, 5it is impossible to know which one to output, so it is definitely most direct to output the name directly:

EBlueprintCompileMode const ETest = EBlueprintCompileMode::Development;
UEnum* const CompileModeEnum = StaticEnum<EBlueprintCompileMode>();
if (CompileModeEnum)
{
    
    
	UE_LOG(LogTemp, Error, TEXT("Current is %s"),
		*CompileModeEnum->GetDisplayNameTextByValue(static_cast<uint8>(ETest)).ToString());
}

  can get the outputLogTemp: Error: Current is Development

Guess you like

Origin blog.csdn.net/Bob__yuan/article/details/117855354