C++ Engine Version Compatibility

I was searching for a preprocessor directive or macro to determine the Engine Version so I could support multiple engine versions with my Plugin.

My initial search landed me on question ‘439440’, and that user said they included the file Runtime/Launch/Resources/Version.h, but I cannot include that file and I don’t think it is the right file to include because its path has the word “Launch”, which makes me think that it is intended to only be used with the Launcher version.

I did some searching on the API and discovered FBuildVersion, but it doesn’t seem to provide compile time information – however, in the definition of it, BuildVersion.cpp, I discovered that it is using the static methods in the FApp class and it has the definition

static const TCHAR* GetBuildVersion();

I wonder if this is the correct method to use, but the functions comment says the string returned “is not assumed to have any particular format”, which means that it probably isn’t a consistent and reliable method for determining the engine version unless you’re just displaying it and not comparing it to anything. However, it does the MajorVersion, MinorVersion integer variables.

I just now noticed the file Runtime/Launch/Version.h contains a huge comment that explains the concepts in UE4 versioning. So, I think FEngineVersion may be the correct thing to use.

Update - I accidentally created a linker error by adding the “Launch” module to the PublicDependencyModule list because I thought that I needed it to be able to include the Version.h header file… I removed the module to fix this error.

LINK : fatal error LNK1181: cannot open input file
UE_4.23\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor.lib

1 Like

So, it seems I didn’t have to include a module or a header file and I was able to use the definition of ENGINE_MINOR_VERSION, e.g.

#if ENGINE_MINOR_VERSION == 23
    // stuff
#endif

Discovered a new requirement from a compiler error

UFUNCTION must not be inside preprocessor blocks, except for WITH_EDITORONLY_DATA

I was able to avoid the UFUNCTION preprocessor error by leaving the declaration of the function outside of any preprocessor definition and only encapsulating the function definition. I had to do this because some code before version 4.23 was WITH_EDITORONLY_DATA, but it wasn’t in 4.23.

MyClass.h

UFUNCTION(BlueprintCallable, Category = Default)
void MyFunction();

MyClass.cpp

#if ENGINE_MINOR_VERSION < 23 && WITH_EDITOR
    void AMyClass::MyFunction()
    {
        // Do editor only stuff
    }
#elif ENGINE_MINOR_VERSION < 23 && !WITH_EDITOR
    // Define something to prevent a compile error
    void AMyClass::MyFunction(){}
#elif ENGINE_MINOR_VERSION == 23
    void AMyClass::MyFunction()
    {
        // Do 4.23 specific stuff
    }
#endif

This worked for me, but I’m not sure if there are any issues with this technique.

1 Like