Logo

dev-resources.site

for different kinds of informations.

Going from Godot 3 to 4 (The Easy Way)

Published at
8/9/2024
Categories
godot
godotengine
plugins
tooling
Author
christinec_dev
Categories
4 categories in total
godot
open
godotengine
open
plugins
open
tooling
open
Author
14 person written this
christinec_dev
open
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? 😅

Godot Code Upgrader Plugin

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.

Godot Code Upgrader Plugin

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).

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

Much better! Now let’s see what happens when I try to run my project.

Godot Code Upgrader Plugin

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.

Godot Code Upgrader Plugin

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.

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

Let’s start with our first script, which is our Player script. Here is the code:

Godot Code Upgrader Plugin

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”:

Godot Code Upgrader Plugin

New code should be upgraded automatically:

Godot Code Upgrader Plugin

As you can see, it made the fixes automatically. Let’s paste these changes into our script.

Godot Code Upgrader Plugin

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.

Godot Code Upgrader Plugin

Let’s run it in the upgrader:

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

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.

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

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!

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

Godot Code Upgrader Plugin

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. 😅

Godot Code Upgrader Plugin

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! 😄

Godot Code Upgrader Plugin


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!

godotengine Article's
30 articles in total
Favicon
Game Dev Diary #1: Starting from zero
Favicon
Online Visual Novel in Godot: Case Study on Sentou Gakuen
Favicon
How to Press and Drag to Reposition a Window in Godot
Favicon
"Surf the Rails in Subway Surfers Online"
Favicon
AR Game ~ Geospatial API Sample ~
Favicon
Navigating the Skies: A Comprehensive Analysis of the Aircraft Engine MRO Market
Favicon
Going from Godot 3 to 4 (The Easy Way)
Favicon
Godot 2D & 3D Prototype Templates
Favicon
Perfecting Game Levels: The Essential Role of Playtesting
Favicon
Reading data from Mysql server
Favicon
Game Development Diary #11 : Second Day Back
Favicon
Game Development Diary #8 : Still Second Course
Favicon
Game Development Diary #7 : Second Course
Favicon
Game Development Diary #5 : Start My "BUMI" Project - Part 1
Favicon
Game Development Diary #4 : First Course Complete
Favicon
10 Useful Tips for Getting the Most Out of Godot
Favicon
Why Godot is a Game Changer in Game Development
Favicon
Game Development Diary #2 : GameDev.tv Course
Favicon
Estruturas de repetição em GDScript
Favicon
Estruturas condicionais em GDScript
Favicon
Boas Pråticas nomeando variåveis e funçÔes em GDScript
Favicon
Kingdom Hearts RE:Back Cover
Favicon
Godot Engine
Favicon
Hash SHA1 at go
Favicon
Let’s Learn Godot 3D by making an Endless Runner Game - Part 1: Project Overview & Setup 👟
Favicon
Let’s Learn Godot 3D by making an Endless Runner Game — Part 2: Environment Setup👟
Favicon
Let’s Learn Godot 3D by making an Endless Runner Game — Part 3: Player Setup & Animations👟
Favicon
Every beginning is hard or my first steps with GODOT - The 1st month
Favicon
BlackJack - Beta version
Favicon
Disney Gargoyles native porting Development Update 🚀

Featured ones: