Switching to Godot 4

How come this post

Godot 4 has its first release candidate on Feb, 8, 2023. I downloaded it and experimented with Godot 4 these days. I tried to convert Thrive to Godot 4 as well but failed (Or stuck, to be concise).

I’d like to list Pros and Cons of switching to Godot 4 here (and list some actions needed) for discussion, and aid anyone who wants to switch Thrive to Godot 4 (or 4.1 or anything).

Overview

I got 2400+ errors after using builtin Godot project converter. Some scene related things are also broken.

Cool features provided by Godot 4

No need for NodePath!!!

Godot 4 supports exporting GodotObject, so there is no longer a need for all those NodePath, Nullable checks and Disposals.

Code Editor

No more unhandled exceptions

Godot now handles any user-unhandled exception for us, the game will not crash due to our fault. Instead, it will print an error:

ERROR: System.NullReferenceException: Object reference not set to an instance of an object.
   at Main.DialogOpenRequested() in /home/ajax/TestGodot4/Main.cs:line 24
   at Main.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret) in /home/ajax/TestGodot4/Godot.SourceGenerators/Godot.SourceGenerators.ScriptMethodsGenerator/Main_ScriptMethods.generated.cs:line 34
   at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr godotObjectGCHandle, godot_string_name* method, godot_variant** args, Int32 argCount, godot_variant_call_error* refCallError, godot_variant* ret) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/CSharpInstanceBridge.cs:line 24
   at: godotsharp_pusherror (modules/mono/glue/runtime_interop.cpp:1303)

C# action implementations

Godot added C# action implementations to signals, making all Node-derived classes partial. Now we can use Button.Pressed += Handler to connect to signals (Also this is now the recommended way); However, they removed signal bindings when connecting signals from C# and altered binding format, from Node.Connect(sig, obj, fun, binding, mode) to Node.Connect(sig, tgt, mode) where tgt = (obj, fun) . So bindings have to be moved to calls.

Autowrap to all Dialogs

Now autowrap function is moved from WindowDialog to Window (now the hierarchy is Popup <- Window <- Viewport <- Node and AcceptDialog <- Window <- Viewport <- Node), so the major part of CustomDialog is now redaudant.

Difficulties to convert to Godot 4

Joybad rework

There’re MASSIVE changes to the Joy-pad controls, from JoystickBlaBla to JoyAxis and JoyButton, so someone very familiar to joypad has to rework this part.

_Process rework

_Process(float delta) goes to _Process(double delta), generating numerous type conversions.

Tween rework

Tween is no longer Node so tween usage should be reconsidered.

Signal rework

No connect-time signal binding anymore. (Mentioned above)

EDIT: From Add a project upgrade tool for Godot 4.0 · Issue #387 · godotengine/godot-proposals · GitHub

conversion of connect() to the new syntax? other.connect("signal", target, "method", [binds]) becomes other.signal.connect(target.method).bind(binds). This is handled in my converter, but the official one handles connections in a different way (which works), so it’s ok too

EDIT 2: It’s BRILLIANT! No proxy anymore (maybe)

control.Connect("focus_entered", GUICommon.Instance, nameof(GUICommon.ProxyFocusForward)),
            new Array(control));

goes to

control.FocusEntered += control.ForwardFocusToNext;

Popup rework

Due to the fact that Popup is no longer CanvasItem, it has no Draw calls. Many custom Popups need to be reworked.

Project conversion errors

We may need to choose a good project converter to avoid renaming all Path to Path3D, all Remove to RemoveAt

Scene errors

AFAIK thrive_theme.tres is not converted properly. e.g. Button styleboxes are missing.

Other changes

  • ColorPicker is completely reworked too

  • Dotnet nullable updates

  • Added Vector2I (<int, int>) for controls (more type conversions)

  • File and Directory reworks (this looks good)

Personal thoughts

It will be pretty hard to switch to Godot 4. However, GUI programming will be benefitted a lot because I think Godot 4’s C# logic is more native and clear.

2 Likes

I’d like to see the difference in performance, whether it’s faster or slower once you do get this running.

I doubt whether I can get this running because I still have 200+ errors in the codebase and a huge amount of scenes that are broken or may be broken. Plus, I’m running out of time (spring semester is approaching)

Maybe you can quickly make some rough small projects so that I can easily convert them and test the performance impact.

That wouldn’t reflect the actual results a project as large such as Thrive may possibly get.

Take your time, this is not urgent.

Very cool stuff coming in Godot 4. Sadly there are really big blocking bugs regarding opening on wrong monitor and not being able to change DPI when moving a window to a different monitor that I experienced. I’ve reported those to Godot but the issues have not been solved (56340 and 56341). Which means that it’ll probably be closer to 4.1 or even later before we can switch once the most serious 4.x new bugs have been fixed.

With those links I just found out we actually have a tracking issue in our repo about this:

This is actually a downgrade for us as we specifically print the instructions to report a bug to us on unhandled exceptions. So I really hope that there’s a way to turn this off.

Can you clarify how this looks? I find it a bit hard to imagine how this impacts us based on just this description.

Update on this: