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

It's impossible to use singletons from tool script #4236

Closed
kubecz3k opened this issue Apr 5, 2016 · 17 comments
Closed

It's impossible to use singletons from tool script #4236

kubecz3k opened this issue Apr 5, 2016 · 17 comments

Comments

@kubecz3k
Copy link
Contributor

kubecz3k commented Apr 5, 2016

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:

  1. Define a "Global" singleton scene with a script
  2. Create another scene with a script in a tool mode, use "Global" singleton somewhere in the script.
  3. Restart Godot (needed for tool scripts to compile )
  4. Open scene with tool script
  5. Observe error in console, tool mode for your script is not working.

Link to minimal example project (optional but very welcome):

@bojidar-bg
Copy link
Contributor

@kubecz3k ~ is the singleton in tool mode too?

@kubecz3k
Copy link
Contributor Author

kubecz3k commented Apr 6, 2016

@bojidar-bg the error is the same regardless if the singleton is in tool mode or not (tried both).

@reduz
Copy link
Member

reduz commented Jun 23, 2016

i don't think singletons are loaded in editor mode, this is intended since singletons can also be scenes.
maybe you can do what you are intending to do in a different way?

@bojidar-bg
Copy link
Contributor

Plugins would come in handy in this case...

@kubecz3k
Copy link
Contributor Author

kubecz3k commented Jun 24, 2016

@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 :)

@vnen
Copy link
Member

vnen commented Jun 24, 2016

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.

@kubecz3k
Copy link
Contributor Author

kubecz3k commented Jun 24, 2016

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.

@neikeq
Copy link
Contributor

neikeq commented Jul 18, 2016

Example project from #5763:

SingletonCompileError.zip
Open this test project, the error appears in the console.

@Zylann
Copy link
Contributor

Zylann commented Jul 18, 2016

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.

@reduz
Copy link
Member

reduz commented Jul 18, 2016

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.

@akien-mga
Copy link
Member

Not critical for the upcoming 2.1, so moving to the next milestone.

@akien-mga akien-mga modified the milestones: 2.2, 2.1 Jul 27, 2016
@alexisgea
Copy link

I'm having the same issue. Hope someone manages to make the change :)

@chanon
Copy link
Contributor

chanon commented Jan 30, 2017

I was trying to use a utility function in my singleton in tool mode and ran into this issue too.

@bojidar-bg
Copy link
Contributor

bojidar-bg commented Jan 30, 2017

I guess we should inject tool-mode singletons when starting editor in main.cpp 😃

@kerskuchen
Copy link
Contributor

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.

@Shadowblitz16
Copy link

this doesn't look like it was added in 3.1

@xsellier
Copy link
Contributor

Hey,

Sorry for the necrobump, but I think sharing this workaround might help few of you.

Loading a singleton that way in a tool script will compile.

onready var MySingleton = get_node("/root/MySingleton");

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

No branches or pull requests