I have a tool that I want to use in Godot 4.3 and 4.6. There is a new class (EditorDock) in 4.6 that I can use to add some nice-to-have features. Obviously, if I add it to my code, it stops compiling in 4.3.
var dock = EditorDock.new()
I’m looking for alternatives to work-around this automatically, for example by using Engine.get_version_info() to check the current version, and only then calling dynamic code.
I tried to use the Expression class, but if I try to evaluate “EditorDock.new()” it fails, and as per this GitHub issue, it seems expressions don’t have access to class names.
I had a similar problem where I wanted to detect if a plugin was available. I ended up with the following solution:
if get_tree().root.has_node("Sound"):
var sound: Variant = get_tree().root.get_node("Sound")
sound.play_ui_sound(sound.get_sound("button_pressed"))
What you can do is this:
var version: Dictionary = Engine.get_version_info()
if version.major == 4:
if version.minor >= 6:
print("Do 4.6 Stuff")
elif version.minor >= 3:
print("Do 4.3 Stuff")
The problem is that unless you know where the script is stored in the system and have a path for it, there’s no way to call new() on a class using a StringName for a class. Without that, you run into the problem you’re seeing.
I think the best thing you can do is create a 4.3 version and release it, and then a 4.6 version.
Well, I didn’t like the solution in that issue (which is only one as far as I can tell), it looks easy to break, but your comment made me reconsider, and it actually worked:
The only problem is that, in versions less than 4.6, it throws an error at load time:
gdscript://-9223353397183162037.gd:1 - Parse Error: Identifier "EditorDock" not declared in the current scope.
So I will do what dragonforge-dev said and run this conditionally.
To answer your question, it is not that I’m trying to make the feature to work in 4.3 and 4.6, I simply support my plugin from version 4.3, and even when making floating panels is a nice feature in 4.6, I don’t consider it critical enough to stop supporting 4.3 just for that.