How to replace BP enums and structs with c++?

How to replace blueprints structures and enums with C++ analogue? I know how to create c++ enums and structs that will be visible to BP, but I cannot find the way to replace references to existing objects :frowning: And I have some structs that referenced more than 100 times…

Make the exact same name in c++ as they were in BP, they will auto-replace and the BP types will have _0 added (the compiler will create new vars with BP types). At least that worked for me with enums, structs might be trickier and you might loose the inner data either way.

I started making them all c++, regardless of what I need. The content-based types also cause tons of issues when renamed / moved / changed after creating when being used and so on. Not very practical for anything bigger than a demo map.

No luck for me. Am I doing it wrong? I have blueprint enum “Enum_RiddleType” and created c++ enum like this:

UENUM(BlueprintType, meta = (OverrideNativeName = "Enum_RiddleType"))
enum class Enum_RiddleType : uint8
{
	NewEnumerator0 = 0 UMETA(DisplayName = "Tutorial"),
	NewEnumerator1 = 1 UMETA(DisplayName = "Limited turns"),
	NewEnumerator2 = 2 UMETA(DisplayName = "Normal"),
	NewEnumerator3 = 3 UMETA(DisplayName = "Hard"),
	NewEnumerator4 = 4 UMETA(DisplayName = "OK"),
	Enum_MAX = 5,
};

/**
 * 
 */
UCLASS()
class TACTIC_API UCEnum_RiddleType : public UUserDefinedEnum
{
	GENERATED_BODY()
	
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Enum)
		Enum_RiddleType My_RiddleType;
};

Now I have two “Enum_RiddleType” and BP one isn’t replaced (original has 4 members).
Maybe there is a method to “replace” it when deleting BP enum? But I don’t see c++ enum in the list to replace - only other BP enums.

Create not only new type, but also a variable in c++ that uses this type, and name the variable exactly as the one you have in your BP. I probably should have been more clear about it. You don’t always need to create a type (just creating a native variable flagged as UPROPERTY(BlueprintReadWrite), but in this case you want to do so anyway, impossible to make a BP Enum variable in c++.

Then your BP should inherit from the native class you created that contains the variable in question (yes you need to create a class and then reparent the BP to use your own class). I found it a good habit, having always a native parent for your BP logic. Derive the native class from what your BP originally inherits (ie. AActor).

Hope this works.

No :frowning: All links become broken. So, the “easiest” way is just to replace all by hands and it’s not funny. I thought migrating from blueprints to c++ is much easier and faster.

Yeah, it appears that structs and enums don’t replace as easily as Other blueprint types. Good thing I caught this relatively early. My issue is that I have to use my structs with templated functions and there’s no way to do that with blueprint structs. So, we’ve learned that it is best just to write all enums and structs as c++ types.

Absolutely

Really? No way to replace blueprint struct with c++ struct automaticlly?

even in version 4.15?

Create Structs in C++ (different name, maybe add a preFix). Now when you delete the BP struct in the editor, it will ask you to replace reference? click on the C++ struct.

how to click on the c++ struct?

Did you get replace references option when you tried to delete the BP struct?

In the view options filter for the “Replace References” list, “Show C++ Classes” is greyed out.

Exactly. 4.22.3 still the same. Only manual work, only hardcore boys!

Finally found a way to do it! Only for enums, but still :wink: Writing here instead of a new answer so that you guys all get a notification. After creating the new enum in code and before launching the editor you must add an entry to the defaultengine.ini config in the [CoreRedirects] section. Goes like this:

+EnumRedirects=(OldName="OLD_ENUM_NAME_HERE",NewName="/Script/PROJECT_NAME_HERE.NEW_ENUM_NAME_HERE",OverrideClassName="/Script/CoreUObject.Enum",ValueChanges=(("NewEnumerator0","NEW_ENUM_VALUE_0"),("NewEnumerator1","NEW_ENUM_VALUE_1"),("NewEnumerator2","NEW_ENUM_VALUE_2")))

Of course, if you have more enum values you just keep adding the redirects between values. Now a little explanation:

OverrideClassName="/Script/CoreUObject.Enum" - this is what you use for a BP created enum. Every enum created in content instead of code has this class.

NewEnumerator0, NewEnumerator1 etc. - every content created enum has values in this fashion. I know you can change the name of each entry, but you are changing the display name, not the actual enum entries.

Verified in 4.23. Yeah I know, took a while, my first answer here is from mid 2016 :wink: Actually wasn’t me who found it, just a fellow programmer on the team who had to replace several BP enums used all over the prototype project. He declined going with manual replace :wink:

Confirming this works!

A note for anyone else trying this, follow everything about this exactly as it’s layed out. Coulda have saved myself several re-builds taking that advice. Set the ValueChanges even if the old names are the same as the new names. And use the NewEnumeratorX naming convention as the old names, I guess it’s how the BP enum is interpreted ¯_(ツ)_/¯ And, I found I had to invert the NewEnumerator indexes to keep existing assignments the same. Instead of 0, 1, 2, 3, 4 I had to go 4, 3, 2, 1, 0. (Even when the BP enum and C++ enum have the same values in the same order.)

E.g.,

+EnumRedirects=(OldName="EPK_StateAction",NewName="/Script/MyProjectName.EPK_StateAction2",OverrideClassName="/Script/CoreUObject.Enum",ValueChanges=(("NewEnumerator4","None"),("NewEnumerator3","NextState"),("NewEnumerator2","PrevState"),("NewEnumerator1","ResetState"),("NewEnumerator0","Restart")))

Sorry for reviving this old thread but it ranks high on google and I have something useful to add:).

As Levitikon217 noticed the “NewEnumeratorXX” names may not be in order or have missing entries and be totally mixed up.
An easy way to find out what maps to what is to go to the Enum asset in the content browser, then in the right click menu under asset actions find export. When you export you get a COPY file and in that file you can read the current mappings and use correct ones in the redirect command.

Had a really old enum that was modified many times and without this trick it was not going to work. Hope it helps someone:).