When I started learning Godot, I started with Godot 3. When Godot 4 came out, a lot of things changed — especially GDScript. To this day, I still type deg2rad
instead of deg\_to\_rad
, and nothing annoys me more than getting that error "Function "deg2rad()" not found in base self. Did you mean to use "deg\_to\_rad()"?"
You’d think I know better by now, but it’s a habit I can’t break. That’s why I decided to play around with a plugin for Godot to help upgrade your GDScript code from Godot 3 to Godot 4. This plugin automates the process of updating deprecated methods, properties, and syntax, ensuring your projects are compatible with the latest version of Godot.
All you have to do is download the plugin, add the folder to your project (your project/addons/upgrader/…), activate it, and paste in the code that you want to convert. Easy enough, right? 😅
Okay, you might not be convinced that this works, so let’s put it to the test by converting one of the very first games I made in Godot 3 to Godot 4 — using only the plugin.
When I started learning, I came across this YouTube video that showed me how to make a simple farming system. It’s not the best looking and I never even completed the tutorial (wow, another unfinished project), but it made younger me feel like I had the power to make Stardew Valley 2.0. 😎
Let’s start by seeing what happens when I open my project that was made in Godot 3.2 the latest version of Godot.
The project setup, the warnings, the blurry textures — it’s giving me the heebie-jeebies. My scripts aren’t organized, my nodes are all over the place- and don’t even get me started on my file management skills. All of these are the artifacts left by beginner me, and I am proud to be the archeologist of this expedition. But we’re not here to critique the project, we’re here to see if the plugin works.
Before we do that, I’m going to upgrade my textures and fix all of the yellow warnings (mostly StaticBody2D nodes requiring collision shapes).
Much better! Now let’s see what happens when I try to run my project.
Uh-oh! I get an error. My scenes can’t run because the scripts all contain outdated code. If only there was a quick fix for that…oh wait, the plugin!
Let’s download the plugin and enable it in the project.
If enabled correctly, there should be a new dock on the left side of the editor. This dock has two parts: a code input and an output panel. We will paste our Godot 3 code in the input panel, and copy our Godot 4 code from the output panel.
Let’s start with our first script, which is our Player script. Here is the code:
As you can see, it uses KinematicBody3D
and move_and_slide()
with a parameter motion. In Godot 4, move_and_slide()
does not call a parameter, and KinematicBody2D
becomes CharacterBody2D
. Let’s see if the plugin can detect these errors and fix it.
Paste in old code and press “Execute”:
New code should be upgraded automatically:
As you can see, it made the fixes automatically. Let’s paste these changes into our script.
No more errors! Okay, let’s do another script. The next script is used to “plant” seeds on a plot of land. As you can see below, it uses BUTTON_LEFT
when it should be MOUSE_BUTTON_LEFT
.
Let’s run it in the upgrader:
You’ll see it made the fixes and no more errors. Let’s do some more. Below it uses rand_range
, when in Godot 4 it would be randf_range
(for floats) or randi_range
(for ints). The plugin made the conversion.
Great! One last one. The code below uses the old method of reading JSON files. The converter will not fully be able to replace your code, as your layout might differ, but it will give you a guide on how to do it. All you have to do is remove your old code, uncomment the guide, and copy in your file path. It’s easy!
With the code fixes out of the way, let’s run the code to see if it works. As I said, I never finished the tutorial, so all I could do in this project was drag seeds over the land to plant them and then after a few seconds they started to grow. Don’t judge me before you look at all the unfinished projects you might have. 😅
With my project working, I can now go back and add the finishing details, and Stardew Valley 2.0 will be live and ready to be published on Steam. Wish me luck! 😄
Conclusion
If you want to use my plugin to upgrade your code or just try it out, you can download it now:
Please know that I might not have picked up all the changes, as there are a lot, so if you find ones that I haven’t added, you can let me know and I will implement those fixes into the plugin!
Top comments (0)