-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept global classes for MainLoop
type in project settings
#41190
Conversation
`application/run/main_loop_type` setting can handle custom global classes (`class_name`). For instance: `MySceneTree`. The setting's default is changed from empty to `SceneTree` as to give some hint of what kind of input is accepted for the main loop type.
Note that you can do this: get_tree().set_script(preload("res://my_scene_tree.gd")) # my_scene_tree.gd
extends SceneTree
func change_scene(path):
print("--- %s ---" % path)
return .change_scene(path) This will work as expected. |
Lines 63 to 71 in dc90b17
If your script inherits directly from |
} else { | ||
main_loop_type = GLOBAL_DEF("application/run/main_loop_type", ""); | ||
} else { // Not based on script path. | ||
if (!editor && !ClassDB::class_exists(main_loop_type) && ScriptServer::is_global_class(main_loop_type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!editor && !ClassDB::class_exists(main_loop_type) && ScriptServer::is_global_class(main_loop_type)) { | |
if (!ClassDB::class_exists(main_loop_type) && ScriptServer::is_global_class(main_loop_type)) { |
Technically it's possible to extend/override the main loop of the editor itself upon restart, but if there are any errors (wrong base type, invalid script etc), then the editor will always crash with an alert (you'd have to modify project.godot
to revert to previous behavior). 😅
Or make it so that it resets the value to SceneTree
if we're running the editor automatically.
Thanks! |
Can this be added to 3.x too or this depends on GDScript changes? |
@eon-s I've tried to apply the same patch to 3.2, patch fails, so needs a dedicated PR for 3.2. If @akien-mga is fine about these changes for 3.2, I could certainly make one. 🙂 I think nothing has changed fundamentally in terms of global classes in 4.0. |
Hi @Xrayez, I'm running Godot v3.3.2.stable on Linux. I tried to run your example which failed to parse the project.godot file because the '@' raised a "ConfigFile parse error at [omitted]/project.godot:6: Unexpected character.". After manually editing the project.godot file, the example throws the same error as my previous try. I hope you can help me with that. |
@RimaitosLab this feature was not backported to Godot As I said earlier, it's possible to backport the feature, but I need an approval from the maintainers before doing the backport. 🙂 |
oh sorry, it seems like I misunderstood the conversation. |
hello @Xrayez @RimaitosLab @eon-s ~ I've tried to backport this feature to 3.x, And it works fine successfully for me. 😄 I've created a pull request here (#52438) |
Fixes #35822.
Helps godotengine/godot-proposals#1349.
The
application/run/main_loop_type
setting can handle custom global classes now (classes exposed withclass_name
keyword). For instance:MySceneTree
.The setting's default is changed from empty to
SceneTree
as to give some hint of what kind of input is accepted for the main loop type.Tested on both editor and release builds.
Some custom scene tree class:
Test project:
global_class_main_loop.zip