[Quick Tip] Renaming C++ Classes without breaking your project

I just did a quick post on how to rename C++ classes without breaking your project. Hope you will find this information useful. :slight_smile:

4 Likes

Is there a way to “Fix up” the redirector, like what happens with materials? :slight_smile:

That’s a neat tip!

Thanks for sharing Satheesh!

:slight_smile:

:slight_smile:

Rama

Very cool tip. :slight_smile:

Wow awesome, i can change some ugly old names now :slight_smile:

Thank you for the tip !

Yeah, ActiveClassRedirects is a very useful feature. Unfortunately this feature (like many other cool features in the engine) is not documented. :frowning:

There’s also ActiveGameNameRedirects that allows you to rename your whole game module. Here’s some example I googled that uses it: BrickGame/DefaultEngine.ini at master · AndrewScheidecker/BrickGame · GitHub

1 Like

While it might be super useful, it didn’t affect the #include sections. Actually…it affected some, which is really weird. Anyways, it’s a thing that should really be easier…I wish they will make a fix. But this current fix should definitely be documented. :confused:

Is there a solution if the entire module was renamed? I am trying to rename a project where we used to have a module ‘A’ that we now want called ‘B’ (for context, ‘A’ was the name of our first customer, and ‘B’ is now the name of our company as it makes more sense moving forward).

I renamed and updated all the C++ side, that part seems fine. But all the blueprints are now failing to compile, not finding the C++ functions that are now in B, complaining “Can’t find file ‘/Script/A’” - trying to find a way to reprocess all those blueprint .uasset to point to /Script/B now… any suggestions?

There’s some documentation on these redirects hidden in the config file:
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Config/BaseEngine.ini#L240

I’m assuming if you rename an entire module, you would use a package redirect, resave all of the assets, then get rid of it again… maybe?

Thank you @Zeblote, this worked really well, with an entry like so:

Now I can either leave this entry permanently, or go find all the assets that are affected and re-save them. That part is a little annoying as there is no good way to process everything afaik.

What if you’ve moved some classes from one module to another, but not all of them? A package redirect wouldn’t work because it would redirect the entire package. I’ve tried the following and it didn’t work.

[/Script/Engine.Engine]
+ActiveClassRedirects=(OldClassName=“OldModuleName.ClassName”,NewClassName=“NewModuleName.ClassName”)

The parent class of my blueprint is now None and my class is not available in the drop-down for reparenting, even though I can create a new blueprint from that same class.

You’re missing the /Script/ part in your redirect. For example:

+ClassRedirects=(OldName=“ClassName”, NewName="/Script/NewModule.ClassName")

I figured out how to do mine. I created a duplicate class in the new module and appended “1” to the name, so ClassName1. Then opened the editor, re-parented blueprints to ClassName1 from ClassName. Saved all in editor and closed editor. Removed ClassName from old module and renamed ClassName1 to ClassName in new module.

Changed redirect to:

And everything worked.

Thanks, will try that.

YEP, that was my problem. Geesh. Thanks Zeblote.

For some reason it didn’t work with all my gameplay tag references. I think I have to make the redirect package work and give up on piecemeal approach.

In 2020, is this still necessary? What is the alternative, just a rename, rebuild and then reparent all your blueprints manually? There must be an engine feature to do this automatically, this is the easiest thing in the world in Unity and Unreal is supposed to have a lot more features than Unity

2 Likes

This is still necessary in 2022 and in UE 5.0.2. This post helped put me on the right track on how to do this for a C++ module refactor to move classes from the main game module to separate modules. The examples below assume just moving a class to a new module but a rename of the class would be analogous - just specify the new class name under NewName.

By trial and error and looking at the numerous examples in https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Config/BaseEngine.ini#L287 from Epic’s own engine refactoring, I discovered the following additional points that weren’t clear to me at least after reading through the earlier replies in this post:

  1. Changes go in an ini file under Config. Must be in a section called [CoreRedirects] Usually Config/DefaultEngine.ini makes the most sense and is what I used.
  2. You use the “fully qualified name” of the class ONLY in NewName and not OldName.
[CoreRedirects]
; ... other redirects
+ClassRedirects=(OldName="MyCppClass",NewName="/Script/MyNewModule.MyCppClass")
  1. For UObject derived classes you omit the actor “A” or object “U” prefix
    So if we have AMyActor in MyGameModule and we move it to MyCoreModule then the line is
+ClassRedirects=(OldName="MyActor",NewName="/Script/MyCoreModule.MyActor")
  1. For struct and enum types we include the FULL name of the class including any prefixes and they also have a different redirect key:
+StructRedirects=(OldName="FMyStruct",NewName="/Script/MyCoreModule.FMyStruct")
+EnumRedirects=(OldName="EMyEnum",NewName="/Script/MyCoreModule.EMyEnum")

I still got some nullptr access errors at runtime playing the game for some of the Uobject properties I refactored so I resaved the blueprints for good measure and the errors went away. This step may not be necessary but it is a good idea to resave the blueprints as then it saves them with the new name and then you will be able to eventually remove the redirects.

7 Likes

For those people (like me), who are trying to follow these steps and still getting lots of warnings from Editor: after closing Editor and adding this line in .ini file, you should first rebuild your project and only then open Editor again :slight_smile:

1 Like

(post deleted by author)