Error with UENUM() Cast of NULL to Package failed

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 ,

Just to make sure, have you declared a variable of your enum type?

eg:

UPROPERTY()
TEnumAsByte<ESomeEnum> MyEnum;

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?

use this code

    UENUM()
    enum PlayerGroundMovement
    {
    	Idle,
    	Run
    };
    
    class AWICCharacter : public ACharacter
    {
GENERATED_UCLASS_BODY()
    public :
    PlayerGroundMovement _PlayerGroundMovement;
    }

It’s the same code I posted above. It’s not work for me. In module. Without usage of UCLASS or anything UE related.

Would you be able to provide more information about where you created your enum (specifically, which header file), and where you are trying to use it?

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.

Hey -

Were any of the suggestions in the thread useful for your or are you still seeing the same error messages? If so do they also occur in 4.6 as well?

Cheers

Hi ,

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.

Thank you.