Migrating an UE Enumerator to C++
I recently had a need to migrate an Unreal Editor Enumeration to C++ and had no intention of manually changing every reference for my own sanity.
I figured out the following table-cloth-swap magic trick to swap enums with minimal manual tweaking:
Preparation:
- Back up everything. Seriously! Do that
git commit
, make a zip, whatever.
- Create your equivalent enum (with UENUM(BlueprintType)
) in C++
- In Unreal Editor rename your old UE Enumeration (eg; stick "Old" on the end) if it has the same name as the C++ enum to make migration and testing easier. Once renamed, right-click your top mod folder and "Fix Up Redirectors"
- Build your mod (Visual Studio build for Development Editor) then load Unreal Editor again and check your C++ enum is behaving and equivalent to the old UE Enumeration - they won't talk nicely yet...
Continued below...1 Reply
The Switcheroo:
- Create or edit
Config\Engine.ini
under your mod's folder, and add the following, modifying it to suit your requirements:
- Replace OldEnumName
with your old UE enum's name, ENewEnumName
with your new C++ enum, ModID with your Mod's ID
- For each enum option, add a ValueChanges entry mapping the old enum entry to the new one. Here's the painful part - the UE Enumeration internally uses IDs NewEnumerator0
, NewEnumerator1
, etc... in the order they were originally added. This means that if enum options were reordered, or deleted, then this won't be a simple sequence. What was the easiest for me was to use FModel to open the mod pak and view the JSON of the old UE Enumeration uasset, which included a mapping of all the NewEnumerator names to labels (although it was oddly missing the last one... 🤔).
- Build your mod (Visual Studio build for Development Editor) again - not sure this step is 100% needed, but doesn't hurt
- Load up Unreal Editor. Now all blueprints using the Old enum should now be using the new enum by name and have the right labels (if you got the ValueChanges
right). If you had a previous node using the new enum natively, you should now be able to connect it to a previously old enum without conversion.
- If all went well, your mod should now build and run! 🎉
Cleanup:
- In Unreal Editor right-click your top mod folder and "Fix Up Redirectors"
- Use the Reference Viewer on the old UE Enumeration - it should be a lot less than before! You should be able to manually clean up these references:
- For Structures edit the Structure and change any variable types using the old enums to use the new one
- For Blueprints I found if I loaded the blueprint and manually compiled and saved it removed the references to the old struct
- If you can get references down to 0, you can delete the old UE Enumeration and remove the EnumRedirects
from Engine.ini
! Congrats!