Using Engine-Version Specific Code
Making sure code runs in the correct version of Unreal
Why Track the Engine Version
This is more of a pipeline concept that film tends to worry about more, but depending on how the code is handled it is entirely possible that multiple Unreal projects could be relying on the same Python codebase.
When supporting multiple versions of Unreal with the same codebase there is the chance that the same code needs to work in multiple versions of Unreal, even if the Unreal API has changed. This page covers an implementation that will allow us to make Unreal version-specific code, allowing us to simultaneously support multiple engine versions.
How to Get the Engine Version
To see the current Unreal Engine version of an Editor session we can use get_engine_version() :
print(unreal.SystemLibrary.get_engine_version())
# Result:
5.2.1-26001984+++UE5+Release-5.2For our purposes, we really only need what's before the - :
5.2.1The EngineVersion class
I wanted to make a class for this that had minimal dependencies, while it is basic in some regards it does the trick.
I'll start with the complete class and then explain the important parts below:
The __init__() function
This class supports a few different options to determine the Engine Version:
if Empty, get the current Editor Session's UE version
Strings, such as "5" , "5.0", or "5.0.0"
Numbers, such as
5.2are also accepted
The value property
This function is what's used to compare itself with others, providing a numeric value that's easier to process
The __lt__() and __eq__() functions
These functions, along with the @total_ordering decorator on the class, define all of our comparisons. We can compare an EngineVersion class with...
Another EngineVersion object
A number, such as
5.2A string, such as
"5.2"
Example Uses
Testing this class in 5.2.1 I get the following results:
Our code can now safely support newer features that come out:
We can use the new 5.5 command while still supporting the method used for older engine versions
Last updated