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 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 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 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 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
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:).