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.
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…
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.
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.
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
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.
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…
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).
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.