How to properly refactor a class name, .gd and .tscn in Godot?

Godot Version

4.4

Question

I have created a class long ago, but then after re-iterating the game code several times, I would like to change the name of the class to something else entirely. Ex. PlayerCar β†’ PlayerVehicle

I am not sure if Godot Editor has a Refactor function? So I used an external app to loop through the whole directory and all subdirectories recursively of my Godot project to replace all occurrences of PlayerCar to be PlayerVehicle in all .gd files. All other file extensions are untouched.

PlayerCar.gd and PlayerCar.tscn are manually renamed to be PlayerVehicle.gd and PlayerVehicle.tscn afterward.

I have already done all above, and I can see the game still runs. Are there any concerns or am I doing this validly?

Help > Programming

Godot can refactor file paths when moved, it will not refactor class_name changes on it’s own. So your tools must have done it correctly.

1 Like

FYI, there is a proposal for adding refactoring tools to the editor. Give it a :+1: if you’re interested, as that helps the Godot team decide what to work on next.

2 Likes

You can also use CTRL+SHIFT+R to find and replace all occurrences of a string within your project. Not exactly a proper refactoring tool, but works alright most of the time.