Xlear
(Xlear)
November 27, 2020, 11:32pm
1
Hello,
i have questions about the given UUserDefinedEnum Class.
How to use UUserDefinedEnum on the right way / should this class be used for ENUMs?
How can i create an ENUM with the given structures from the UUserDefinedEnum Class with the name of eg. ETestTypes?
What is the purpose for a .cpp file? (In my knowledge, a cpp file is not needed for ENUMs)
I hope someone knows about the “UUserDefinedEnum Class”
Thanks for your help -
ETestTypes.h:
#pragma once
#include "CoreMinimal.h"
#include "Engine/UserDefinedEnum.h"
#include "ETestTypes.generated.h"
/**
*
*/
UCLASS()
class PROJECTA_API UETestTypes : public UUserDefinedEnum
{
GENERATED_BODY()
};
ETestTypes.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "ETestTypes.h"
1 Like
super confused why you would like to inherit from UUserDefinedEnum,
if you just want to create a custom enum just do:
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "YourEnum.generated.h"
UENUM(BlueprintType)
enum class EYourEnum : uint8
{
Something,
SomethingOther,
SomethingElse
};
1 Like
Xlear
(Xlear)
December 4, 2020, 10:43pm
3
thanks for your answer. in general you are right, but because epic itself describes this class that way (and the first point is very interesting)
EnumType is always UEnum::ECppForm::Namespaced (to comfortable handle names collisions)
always have the last ‘_MAX’ enumerator, that cannot be changed by user
Full enumerator name has form: ‘="">::’ An Enumeration is a list of named values.
Sure but name collisions are only a problem for enums, not enum classes, enum classes are strongly typed.
the _MAx for enumerations you can add yourself
UENUM(BlueprintType)
enum class EYourEnum : uint8
{
Something,
SomethingOther,
SomethingElse,
YourEnum_Max UMETA(Hidden),
};
the names are a little harder, but in most cases, you don’t need names, if you just want to use the enum as a state value.
I think the only purpose of UUserDefinedEnum is to be able to create enums in the editor, which if you are using C++ anyway is not really necessary for you. In general, if you are using C++ it’s a good practice to define all your types in C++, enum classes, structs. This allows you to use them in C++ and in blueprints.
4 Likes
Xlear
(Xlear)
December 4, 2020, 11:18pm
5
ok, thanks for the detailed explanation