UStruct: type must be a UCLASS, USTRUCT or UENUM

I’m probably missing something simple but I can’t find it. The struct is marked as USTRUCT() but still it complains about it not being a USTRUCT. It’s not caused by the TArray because removing that still gives the same error. Also I can use the struct FCrusherTrigger in blueprints without a problem at all. But c++ gives me an error.

// Structs.h
USTRUCT(BlueprintType)
struct FCrusherTrigger
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CrusherTrigger")
	ECollisionShapeEnum CollisionType;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CrusherTrigger")
	FTransform RelativeTransform;

	FCrusherTrigger()
	{
		CollisionType = ECollisionShapeEnum::CollisionShape_Box;
	}
};


...

// BaseCrusher.h
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "BaseCrusher")
TArray<FCrusherTrigger> TriggersSetup; // <<<<<<<<<<<<< error here

Unrecognized type ‘FCrusherTrigger’ -
type must be a UCLASS, USTRUCT or
UENUM

1 Like

Found the problem. It’s another unreal bug. It’s the same as: https://answers.unrealengine.com/questions/424938/enum-parameter-with-ufunction.html

Basically Enums & Structs included through the project header will not always (or never) work when used in conjunction with UFUNCTION or UPROPERTY.

The fix is to include a manual-include (so basically uncluding it twice!) for it to work with the unreal headertool when it’s marked as a UFUNCTION or UPROPERTY. Note that Visual Studio does recognize the struct and so does the Unreal Editor but the UnrealHeaderTool does not…

1 Like

Hi. I’m having a similar problem. What do you mean by “including it twice”

In the header twice in the row with USTRUCT() above both or UPROPERTY()
, or one of each?

1 Like

I was getting this error when the file where I use the USTRUCT type didn’t have an explicit include to where the USTRUCT was defined. Once I added an explicit include, it worked.
I would have expected VS to just say the type didn’t exist at all under those conditions, which is why I didn’t look there first. But the original statement was correct. You’re including a class/struct that’s defined somewhere, and you haven’t included that definition into the file where you’re using it.

1 Like

Hi Eidur,

This bug only occurred for me when having #include “Structs.h” in the project header file and then the class which uses the struct includes the project’s header file (instead of including Structs.h directly). So the fix is to include it directly or at least both. Example:

Inside the cpp file that needs to use the struct you add these two includes:

// If MyProjectHeader.h also includes Structs.h the UHT will not recognize it.
#include "MyProjectHeader.h" 

// This include is the workaround. Because you already included this by including the project header file, Structs.h is essentially included twice but the #pragma once will stop that. However this will fix the UHT not recognizing it.
#include "Structs.h"

However this was ~1.5 years ago in UE4.11 so I’m not sure if the bug was fixed in the meantime.

1 Like

Hi, I have currently the same problem, I declared my struct in one of my header and I got the error. I tried to create another separately header but nothing change.
`#pragma once

#include “GameFramework/Actor.h”
#include “CameraDirector.generated.h”

UCLASS()
class HOWTO_AUTOCAMERA_API ACameraDirector : public AActor
{
GENERATED_BODY()

public:

};

USTRUCT()
struct FCameraStruct
{
GENERATED_USTRUCT_BODY()

	UPROPERTY()
	AActor* Camera;


};
`

Our group keeps hitting the same problem, but it seems like every time the solution ends up being something wrong in an entirely other file. I’d recommend commenting out the UPROPERTY for whatever is causing it and trying to see if any other problems arise, then solve those and come back to it.

2 Likes

For anyone else who stumbles into this problem, this approach worked for me: Remove UPROPERTY macros, fix other compiler errors, then put UPROPERTY back

Hello, finally got a working (and clean) solution to this, yet another, unreal programming problem…

The problem:
For some reason, the compiler doesnt like us upropertying its engine’s enums and or structs and complains with a :
" Unrecognized type ‘ENUM or STRUCT’ - type must be a UCLASS, USTRUCT or UENUM ".
Removing the uproperty things makes it work, but…

The solution:
Add TEnumAsByte<your enum>

Example:

Instead of:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SafeSpawnLocator RayCast Config")

TArray<EObjectTypeQuery> SpawnableLayers;

do:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SafeSpawnLocator RayCast Config")

TArray<TEnumAsByte<EObjectTypeQuery>> SpawnableLayers;

This compiles and shows the variables in the inspector \o/

Engine Version: 4.19

3 Likes

I had a circular reference of headers that was triggering this error.

1 Like

this issue can be caused by several reason which my issue is caused by circular dependency!

Circular Dependency basically means that two Header files are trying to include each other, and therefore the compiler can’t work out which one to compile first.

It’s a bit of a pain to resolve since it means reworking your #includes slightly, but Forward Declarations can help with this a lot (but only work if you’re not calling functions on or accessing the declared class).

https://forums.unrealengine.com/development-discussion/c-gameplay-programming/60832-circular-dependency-detected-for-filename

link text

3 Likes

Removing the UPROPERTY for offending class memeber and handling the remaining bugs fixed the issue for me as well… but putting UPROPERTY back in made the same issue resurface.

LIKELY CAUSE: the two struct members I was trying to set as a UPROPERTY were TSharedPtr and TWeakPtr (for defined USTRUCTs) My guess is that my somewhat sloppy design decision in declaring these smart pointers as UPROPERTY is the problem.

  • NOTE: In principle the TSharedPtr
    should own the USTRUCT and manage
    garbage collection. But UPROPERTY is
    a much deeper step into the Unreal
    Engine and does not even work with
    plenty of built-in types (i.e.
    integers besides uint8 and int32 will not
    work as blueprint accessible).

I had the same case
I think it’s a include error By UnrealHeaderToll.
The problem was solved by removing the file that plays the same role as the PCH file and including it directly in the CPP.

I encountered this issue after renaming a class.
Once I renamed the class and changed all references to the correct new name I encountered this issue.

The only way to fix was to include the header twice. Once from another header that had it in its header and the other directly (prior to name change it didn’t need a direct include) . I even refactored to make sure I declared it once and then forward declared it but it wanted an explicit include to the header to make it happy. It compiles fine but a little bizarre. This is in 4.26.

this solved my problem, thx a lot