Replace Blueprint Enum and Struct with C++

Hi,

I am trying to port a BluePrint project partly to C++. The reason is that Blueprint Structs do not allow inheritance, unlike C++ Structs.

It seems like I can’t use Blueprint Enums as variables in C++ Structs, so I also had to recreate the Enums and Structs needed by that Struct in C++ as well. Now I have some Structs and Enums in Blueprint and C++, so I have to replace the Blueprint versions everywhere.

But that seems really exhausting, the replacing tool doesn’t allow to replace a BP Struct with a C++ Struct or a BP Enum with a C++ Enum and it looks like I have to replace every occurrence by hand. Which would be fine, but I didn’t find a way to show the occurrences. Using the reference viewer or the delete dialog shows you the blueprints, but you still have to look for the occurrence inside that blueprint, which is the really exhausting part.

Do I overlook a function or is it really so difficult?

Hello Relax92,

As far as I know, C++ doesn’t know about Blueprints data structures (either structs or Enums), but blueprints know all about C++ (which are under UPROPERTY / USTRUCT / UENUM and so on).

This makes that usually move a Blueprint Project to a C++ means redo most of the structures and replace them by hand making sure there are not name or functions conflicts which will made the blueprint not compile anymore.

More over, structs and enums usually have some issues on HotReloads, since the blueprint variables doesn’t update properly but still have the old build as a hotreaload. (I Fix this restarting the editor, I don’t know if there is a proper way).

So the answer (as far as I know) is yes, you need to replace all the old structures to new ones by hand.

I’m sorry to not provide a magic functionality to boost the change, (maybe some others know)

Thanks, at least I know now that there really is no better way.

I literally just went through this, and tried to do it the hard way. I re-created all my structs and enums in C++, then renamed the BP ones to *_Old so I could find them, and set about changing them.

This was a mistake.

Every single pin, every single conversion node, retained the old types.

Then, when I thought I was all done, I had to rename my enum indices and do it all again. I couldn’t find every single instance and my log was full of errors. Blueprints just retain a LOT of data that you would think would change automatically. It doesn’t.

That’s when I was shown the wonder of Core Redirects. You can pretty much use the examples from that page and just change the values. They go in Engine.ini and when you load your project it’ll rewrite every matching blueprint type to be the corresponding C++ type instead. Works for classes, enums and structs. Give it a go.

5 Likes

Wow that’s amazing, thanks for sharing your knowledge!!!

Maybe I’m doing something wrong, but it doesn’t work for me.

I put following line into “/Config/DefaultEngine.ini”


PropertyRedirects=(OldName="MyChildBPClass.MyVariable", NewName="MyParentCPPClass.MyVariable")

Then I open editor, open /Gameplay/MyChildBPClass and it shows me warning “Found a member with a conflicting name (MyVariable) - changed to MyVariable_0”. If I delete MyVariable_0, it shows confirmation dialog and deletes all usages of MyVariable_0 in the class (it doesn’t even grey it out, which would be really convenient). I expected it to use MyVariable instead.

I tried to put into PropertyRedirects names like “MyChildBPClass_C.MyVariable”, “/Gameplay/MyChildBPClass.MyVariable”, “/Game/Gameplay/MyChildBPClass.MyVariable” and all variations.

Maybe you’ve already solved this but, I’m wondering if what you describe is really a PropertyRedirect? Looks rather like a ClassRedirect, you are changing the class name but not the property, it is called MyVariable in both cases. The class redirect would be.


+ClassRedirects=(OldName="MyChildBPClass_C", NewName="MyParentCPPClass")

Yeah what you want are similar to Class and Property redirectors, Struct and Enum Redirectors.

+StructRedirects=(OldName=“OldStructName”,NewName=“NewStructName”)
+EnumRedirects=(OldName=“ENumbers”,NewName=“ELetters”,ValueChanges=((“NumberTwo”,“LetterB”),(“NumberThree”,“LetterC”)))

You put them in the same place as the other redirector types (DefaultEngine.ini) in the [CoreRedirects] section.

Because you’re converting from blueprint to native, the OldName may need to include some additional path information like “/Game/…/Enum”. The new name may also need some path information like “/Script/ModuleName.NewTypeName”.