dev-resources.site
for different kinds of informations.
Going from Godot 3 to 4 (The Easy Way)
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!
Featured ones: