Skip to content
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

Set global script classes on Godot 4 #335

Open
MateuSai opened this issue Aug 28, 2023 · 3 comments
Open

Set global script classes on Godot 4 #335

MateuSai opened this issue Aug 28, 2023 · 3 comments
Labels

Comments

@MateuSai
Copy link

Hi, in Godot 4, ProjectSettings.get_setting("_global_script_classes") returns nil. Seems like the equivalent is ProjectSettings.get_global_class_list(), however, I can't find a function to set the global class list. So, script extensions don't work on Godot 4 at the moment. If anyone finds a solution, please let me know.

@Qubus0
Copy link
Collaborator

Qubus0 commented Aug 28, 2023

So, the global classes are moved to .godot/global_script_class_cache.cfg in this pr godotengine/godot#70557
This pr here has a way to open them with ConfigFile, and it should be possible to save it with this as well godotengine/godot-docs#6632
I'm not sure if the game still needs to be restarted - would be nice if not, but I doubt it.

All that aside, if the ModLoader is installed by the developer, the global class method is not needed for script extensions, since all global classes are already added by the editor and included on export. This could only be an issue for the self setup.

@KANAjetzt KANAjetzt added the 4.x label Sep 16, 2023
@KANAjetzt
Copy link
Member

KANAjetzt commented Sep 22, 2023

This is the function we are talking about, right?

# Reload all children classes of the vanilla class we just extended
# Calling reload() the children of an extended class seems to allow them to be extended
# e.g if B is a child class of A, reloading B after apply an extender of A allows extenders of B to properly extend B, taking A's extender(s) into account
static func _reload_vanilla_child_classes_for(script: Script) -> void:
if script == null:
return
var current_child_classes := []
var actual_path: String = script.get_base_script().resource_path
var classes: Array = ProjectSettings.get_setting("_global_script_classes")
for _class in classes:
if _class.path == actual_path:
current_child_classes.push_back(_class)
break
for _class in current_child_classes:
for child_class in classes:
if child_class.base == _class.class:
load(child_class.path).reload()

@MateuSai
Copy link
Author

No, the problem is the setting the global classes since it seems there is no straightforward equivalent in Godot 4. In the function you mention I replaced the line 121 with var classes: Array = ProjectSettings.get_global_class_list().

But as Qubus0 said this is only a problem with the self setup. I got it working without changing the lines where the global classes are set, since the code is not being executed, I don't get any error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants