Issues with ANY_PACKAGE used in FindObject

In trying to get a FString representation of one of my Enums, I am getting a compile error:

error C2664: ‘T *FindObject(UObject *,const TCHAR *,bool)’: cannot convert argument 1 from ‘UPackage *’ to ‘UObject *’

I have not been able to figure out what I am missing to make this work.

usage:

template<typename TEnum>
static FORCEINLINE FString GetEnumToString(const FString& Name, TEnum Value)
{
    const UEnum* enumPtr = FindObject<UEnum>(ANY_PACKAGE, *Name, true);
    if (!enumPtr)
    {
        return FString("Invalid");
    }
    return enumPtr->GetNameByValue((int64)Value).ToString();
}

Of course, I immediately fixed it after posting the question.

I simply changed

#include "CoreMinimal.h"

to

#include "EngineMinimal.h"

Can anybody tell whats the difference? I searched the whole VS Solution for ANY_PACKAGE and the only thing that comes up is: #define ANY_PACKAGE ((UPackage*)-1) in ObjectMacros.h

Changing the include should not make any difference, as that is the only definition there is.

My code (plugin code) compiles fine for development, but the error comes up when trying build the plugin for shipping in 4.20. Also strange: the problem seems to occour in 4.16 already but in 4.19 I had no issue with it.

@Rumbleball : The unity build feature of Unreal (which merges a lot of .cpp files into a single file during compilation for shorter compile time) can hide missing includes. Probably some other .cpp file got into the same unity compile chunk, which had the include that was actually missing in the first file the whole time.

The include should be fine as it finds the definition. The problem is that the compiler can`t resolve UPackage to UObject.

The culprit seems to be specifically StructOnScope.h, which is indirectly included by EngineMinimal.h, but not CoreMinimal.h. That file does mention the UPackage class. I have not looked further though.