Best Way To Change Class Name (including filename, etc)

It seems whenever I need to change a class name, I get into a world of hurt. For example, I changed ARealLifeCharacter to ADefaultCharacter, file names went from RealLifeCharacter to DefaultCharacter (.cpp and .h). Now half my blueprints are broken and stuff. I also went into the config files and noticed my old class ARealLifeCharacter is being referenced all over the place.

What’s the correct procedure to change a class name?

Thanks!

Edit:
I noticed this in the Engine config .ini file:


[/Script/Engine.Engine]
+ActiveGameNameRedirects=(OldGameName="TP_FirstPerson",NewGameName="/Script/RealLife")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_FirstPerson",NewGameName="/Script/RealLife")
+ActiveClassRedirects=(OldClassName="TP_FirstPersonProjectile",NewClassName="RealLifeProjectile")
+ActiveClassRedirects=(OldClassName="TP_FirstPersonHUD",NewClassName="RealLifeHUD")
+ActiveClassRedirects=(OldClassName="TP_FirstPersonGameMode",NewClassName="RealLifeGameMode")
+ActiveClassRedirects=(OldClassName="TP_FirstPersonCharacter",NewClassName="PlayableCharacter")

Does this need to change, too?

Been there, not a place I want to visit again. It gets even better if you rename a class that a BP is inheriting from. It won’t ever open again until it finds that original class again. That config bit you posted is actually supposed to be a sort of “old to new” forwarder for exactly such cases but I personally never got it to work. I just took it as a lesson and went through the reconnecting-everything-in-blueprints process.

It’s understandable of course, but surely one of the more annoying aspects of the tight coupling between BP’s and C++. The ultimate advice is simply DO NOT RENAME OR DELETE CLASSES. :slight_smile:

“grep -r” and “sed -e -i” are your friends :slight_smile:

Yes, when you rename a class you need to set up a redirect so that the linker can point to the correct root when it is loading existing objects.

For a “simple” case like yours with renaming a class you will need to add just the ActiveClassRedirect. Something like:

+ActiveGameNameRedirects=(OldClassName=“RealLifeCharacter”,NewClassName=“DefaultCharacter”)

If there are any existing redirects that point to RealLifeCharacter as the NewClassName, you’ll want to switch those to be DefaultCharacter as well.