This isn’t going to be easy to repro, but it’s now happened to me a couple of times. So far I believe it has only occurred when working with an engine source build.
issue is this: sometimes, having added a header file to project containing a definition of a new reflected type, UHT will fail to recognise it and generate an ‘Unrecognized type’ error at a line in a file which references it. For example, I add following file:
// MyNewType.h
#pragma once
#include "MyNewType.generated.h"
USTRUCT(BlueprintType)
struct FMyNewType
{
...
};
And modify an existing file to reference it:
// MyExistingType.h
#pragma once
#include "MyNewType.h"
#include "MyExistingType.generated.h"
UCLASS()
class UMyExistingType: public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
FMyNewType NewTypeProp;
...
};
I then (once in a while) get an ‘Unrecognized type’ error at line declaring property. No amount of cleaning project or regenerating project files seems to help when this happens.
Something that may help track this down. In latest case, file containing property did not directly include newly added file. It included it via an intermediate header file, which (not sure if this is relevant or not) was a standard header - no reflection/.generated include. include paths themselves were correct - if I commented out UPROPERTY line above actual member variable, everything built fine. Yet I solved the ‘Unrecognized type’ error by adding a direct include to new header file in header where I declared property.
Unfortunately I don’t think issue is a simple one. I have a parallel group of classes which I had already added and have no issues with despite not including header directly. Also, first time I encountered this issue I spent hours stepping through UHT code in debugger, only for it finally to start working on one run through without me apparently changing anything. I suspect perhaps UHT may be caching some information from previous runs to avoid regenerating everything from scratch each time (?) and perhaps issue is related to this.
Apologies for wall of text for what is not a pressing issue, but perhaps it will help someone track it down.
EDIT: Adding code demonstrating current situation
// TheTypeFile.h
#pragma once
#include "TheTypeFile.generated.h"
// NOTE: Header name and type name are not same.
// May be irrelevant, anyway at this point renaming it to be same makes no difference.
USTRUCT()
struct FTheType
{
GENERATED_BODY()
...
};
// TheIntermediate.h
#pragma once
#include "TheTypeFile.h"
// TheReflectedIntermediate.h
#pragma once
#include "TheTypeFile.h"
#include "TheReflectedIntermediate.generated.h"
USTRUCT()
struct FAnyReflectedType
{
GENERATED_BODY()
};
// TheContainer.h
#pragma once
#include "TheIntermediate.h"
// NOTE: Uncomment either of these and error disappears
// #include "TheTypeFile.h"
// #include "TheReflectedIntermediate.h"
#include "TheContainer.generated.h"
UCLASS()
class UTheContainer: public UObject
{
GENERATED_BODY()
public:
UPROPERTY()
FTheType TheProperty; // UHT ERROR HERE: Unrecognized type 'FTheType'
};