Hello. I’m trying to create an enumeration. I use this code
UENUM()
namespace ESomeEnum
{
enum Type
{
TestTest
};
}
But I’m getting a runtime error:
Cast of NULL to Package failed
This problem starts in MyModule.generated.cpp - in one of the generated functions, namely
UPackage*
Z_Construct_UPackage_MyModule()
Jumping with breakpoints I found that my enum type is not registered in UObjectHash.cpp ObjectHash, i.e. HashObject() function is not called for my object. But why?
Hi ,
No, I didn’t declare it in this way. Why should I? I planned to use this enum as key in TMap. Also this enum should be used in module and in usual class, not in UCLASS. Is it possible?
UENUM()
enum PlayerGroundMovement
{
Idle,
Run
};
class AWICCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
public :
PlayerGroundMovement _PlayerGroundMovement;
}
So there is a hack you can do here to make this work…
I have a header file called GameNameTypes.h
here is the code I have:
#include "RaccoonTypes.generated.h"
#pragma once
UENUM()
namespace ESomeEnum
{
enum Type
{
TestTest
};
}
UCLASS(Abstract, CustomConstructor)
class URaccoonTypes : public UObject
{
GENERATED_UCLASS_BODY()
URaccoonTypes(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) {}
};
Essentially the Custom UObject forces the types internally to this “Type” to be properly constructed, and then able to use this type correctly, The main issue here is the the headerfile you are generating is considered a package and thus needs to be constructed.
We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.