-
-
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
It's impossible to use singletons from tool script #4236
Comments
@kubecz3k ~ is the singleton in |
@bojidar-bg the error is the same regardless if the singleton is in tool mode or not (tried both). |
i don't think singletons are loaded in editor mode, this is intended since singletons can also be scenes. |
Plugins would come in handy in this case... |
@reduz Well in general I have a lot of 'helper' functions defined in singletons/globals. Those are the functions which I'm using in a daily basics and it's quite an issue for me... It would be ok for me if my singletons should be a tools as well... Maybe I should convert them to plugins as @bojidar-bg suggested but I'm not familiar with plugins api yet so I'm not sure if this is the way. In next week I will have time to explore all those fancy features that 2.1 will provide :) |
I'm not sure if plugins can talk to each other. A way to make a set of plugins with common data would be an interesting feature. I don't think this is a "bug" though, it simply wasn't designed this way. |
Well the idea that difference tool keyword from plugins for me, is the possibility for every scene to have some small code that runs in editor, usually linked to getters/setters methods. Currently this is impossible because those scenes simply wont compile. While the plugins are more 'general use' or 'bigger' chunks of code. |
Example project from #5763:
|
Workaround: if your helper functions don't access the state of the singleton, you can make your functions static and do this in the script where the singleton is used: # HOTFIX tool scripts cannot compile if they use singletons
const Groups = preload("groups.gd") However if the script also uses another game-related singleton, this is becoming a problem, unless you can separate the tool-related part in another node. |
Maybe we could add a flag "tool" to singletons (besides global) to get this to work (load them if the flag is present). If anyone wants to do this, please feel free to do it. |
Not critical for the upcoming 2.1, so moving to the next milestone. |
I'm having the same issue. Hope someone manages to make the change :) |
I was trying to use a utility function in my singleton in tool mode and ran into this issue too. |
I guess we should inject tool-mode singletons when starting editor in |
It would definitely be useful to use singletons in tool mode to avoid cluttering a lot of scripts that are game objects as well as tools with preloads. |
this doesn't look like it was added in 3.1 |
Hey, Sorry for the necrobump, but I think sharing this workaround might help few of you. Loading a singleton that way in a
|
Operating system or device:
Ubuntu, Godot 2.01
Issue description (what happened, and what was expected):
When you define a script that have tool keyword on the top, and you use in this script any singleton it wont compile because of an error: (where "Global" is my singleton)
SCRIPT ERROR: GDScript::reload: Compile Error: Identifier not found: Global At: res://Gameplay/Levels/BaseLevel.gd:151. ERROR: reload: Method/Function Failed, returning: ERR_COMPILATION_FAILED At: modules/gdscript/gd_script.cpp:1894.
You won't be able to use singleton script with
get_node("/root/Signleton")
either.Steps to reproduce:
Link to minimal example project (optional but very welcome):
The text was updated successfully, but these errors were encountered: