0 votes

Is there a way to change all snake cases to camel cases for variables and node names in the whole project?
We initially didn't decide on conventions, and the naming conventions are starting to mix.

Godot version 3.4
in Engine by (27 points)

I am not familiar with what a snake and camel case is, but if you have script open in the Editor, you do a Find/Replace for all scripts in the document by doing:

  • Click "Search"
  • Click "Find in Files..." in the drop down menu
  • Enter your search string in the 'Find' field
  • Select "Replace..."
  • and then enter your replacement text to replace all occurrences

Doing the above approach blindly is dangerous, since you might introduce undetected syntax issues (or worse, logic error that don't make a compilation error) in your scripts. So I suggest you review the preview pane at the bottom before replacing everything (it will show you all text instances that match your query that will be replaced)

Thank you, this is useful up to a couple hundred variables since I have to check each variable if it is safe to change, but it becomes unfeasible if there are thousands or even tens of thousands of variables. I wish there were a option in the godot UI to change the cases, or a script or vim-macro that does it automatically.

1 Answer

+1 vote
Best answer

Google how to do godot refactoring. Godot does not have a built in ability to do that as far as i know but you may get some ideas.

by (805 points)
selected by

This is unfeasible when there are tens of thousands of variables. The only thing I need is to change it automatically to camel cases, not refactor the whole project.

Renaming variables is considered refactoring. If you have thousands then it's worth writing a script (you can use godot) to locate all the snake variables and replace with camel case.

What I would do, is create a script that reads the gd files line by line looking for var and creating a dictionary sorted descending order. Then using the dictionary find all the matching variables in the gd code and replace with camelcase outputting to another file.

You can use regex class to make it easier to find the string variables. https://docs.godotengine.org/en/stable/classes/class_regex.html

Then repeat for other files such as tscn and project.godot

That worked, thank you.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.