Download

Show Enum via UPROPERTY in editor

Hello guys,

i am trying to show off the available Blendmodes inside the editor and trying that like UE describing it in their Coding Standards.
(I am using UE 4.5)
in myFile.h
outside UCLASS


UENUM(BlueprintType)
enum class EMyBlendMode : uint8
{
	BLEND_Opaque UMETA(DisplayName = "Opaque"),
	BLEND_Masked UMETA(DisplayName = "Masked"),
	BLEND_Translucent UMETA(DisplayName = "Translucent"),
	BLEND_Additive UMETA(DisplayName = "Additive"),
	BLEND_Modulate UMETA(DisplayName = "Modulate"),
	BLEND_MAX
};

this is just copied out of EngineTypes.h from EBlendMode, then i am doing this Inside UCLASS


UPROPERTY(EditAnywhere, Category = BlendMode);
EMyBlendMode TestMyBlendMode;

Intellisense do not complain but when i try to build that i am getting this at line where (EMyBlendMode TestMyBlendMode) stays.


Error	1	error : In MyFile.h: Member variable declaration: Missing variable type	....  

I dont know why this happens, because every example i found looks exactly like mine.
Would be nice if someone could help me with this.

kind regards
Wallhalla

Hello there! Not 100% sure if this is the issue, but I think you are defining your enum incorrectly. I suggest setting it up like this tutorial on the wiki https://wiki.unrealengine.com/Enums_For_Both_C%2B%2B_and_BP. Notice how you define the enum inside a namespace and define the enum with name “Type”. I think this is how UE4 expects you to define enums, again I am not 100% sure, but it is worth a shot trying that out as it is what I use and it does work!

Hope this helps!
Connor

Hi Connor,

thanks for your reply. Well i tried both methods, like mentioned here: CodingStandard.

Both resulting the same error. Now i edited my code like this: (old enum)


UENUM(BlueprintType)
namespace EAlthasBlendMode
{
	enum Type
	{
		Opaque			UMETA(DisplayName = "Opaque"),
		Masked			UMETA(DisplayName = "Masked"),
		Translucent		UMETA(DisplayName = "Translucent"),
		Additive		UMETA(DisplayName = "Additive"),
		Modulate		UMETA(DisplayName = "Modulate"),
		BLEND_MAX,
	};
}

and in class with:

ahhhhhhhhhhhhhhhh…

omg… look at

sorry to have bothered you…

please mark as solved…

ok, a new problem occured.

I want to make ESimpleElementBlendMode from SceneTypes.h as a UENUM(BlueprintType) which is currently missing.

Thats why i tried to just add like follows:

/** Blend modes supported for simple element rendering */




// in SceneTypes.h
UENUM(BlueprintType)
enum ESimpleElementBlendMode
{
	SE_BLEND_Opaque = 0,
	SE_BLEND_Masked,
	SE_BLEND_Translucent,
	SE_BLEND_Additive,
	SE_BLEND_Modulate,
	SE_BLEND_MaskedDistanceField,
	SE_BLEND_MaskedDistanceFieldShadowed,
	SE_BLEND_TranslucentDistanceField,
	SE_BLEND_TranslucentDistanceFieldShadowed,
	SE_BLEND_AlphaComposite,
	// Like SE_BLEND_Translucent, but modifies destination alpha
	SE_BLEND_AlphaBlend,
	SE_BLEND_RGBA_MASK_START,
	SE_BLEND_RGBA_MASK_END = SE_BLEND_RGBA_MASK_START + 31, //Using 5bit bit-field for red, green, blue, alpha and desaturation

	SE_BLEND_MAX,
};

and now i am getting:

what does that mean?

kind regards
Wallhalla

Wallhalla you should follow the first approach which is the most correct.

so change
“enum ESimpleElementBlendMode”

by
“enum class ESimpleElementBlendMode : uint8”

I think the UHT build is complaining about the missing uint8.

Enum class support is actually a very recent addition to the engine and not more or less “correct” than a plain old enum.

I’d look at the SE_BLEND_RGBA_MASK_END = SE_BLEND_RGBA_MASK_START + 31, assignment. The header tool is picky about how you use enums and is probably choking on the backreference. If you want to bitwise operations using an enum, you should avoid making it an UEnum. Plus, you probably don’t want those values showing up in an editor drop down menu for that enum.

Arent you supposed to to something like

This post helped me to get along with custom enums

Special thanks to your answer. Well i think the case may be this enum is just not ready for UENUM() since SceneTypes.h is from Epic, i did no modifications there, but they do not set up the UENUM() for that. So
i believe i could try as hard as i can, but wont get no results :slight_smile:

At least Epic says so:

“Enum classes are supported by all compilers and encouraged as a replacement for old-style namespaced enums, both for regular enums and UENUMs.”

Besides same functionality, I would opt for the recommendations of any API provider.

And from a personal point of view I don’t like to use namespaces for something thats not intended (I know the safe_enum idiom and fellows, but strong enums are here to overcome ancient limitations and workarounds).

Add a cast to uint32 to your assignment.

SE_BLEND_RGBA_MASK_END = SE_BLEND_RGBA_MASK_START + 31

SE_BLEND_RGBA_MASK_END = (uint32) (SE_BLEND_RGBA_MASK_START) + 31

or

SE_BLEND_RGBA_MASK_END = (uint32) (SE_BLEND_RGBA_MASK_START + 31)

enum class also has a significant advantage in that they can be forward-declared which can get you out of some include dependency problems, and improve compile time. They are also just a bit less typing to use.