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

Calling a singleton function doesn't show autocompletion in the editor #48624

Closed
nonunknown opened this issue May 10, 2021 · 13 comments · Fixed by #85382
Closed

Calling a singleton function doesn't show autocompletion in the editor #48624

nonunknown opened this issue May 10, 2021 · 13 comments · Fixed by #85382

Comments

@nonunknown
Copy link
Contributor

Godot version:

3.3 stable

OS/device including version:

Windows 10 x64

Issue description:

When the user have a script and wants calls a function from this same script it shows the func description like this:
image
But when you call a func from a Singleton, this hint doesnt show:
image

Steps to reproduce:

  • Create a Singleton
  • Create a Normal Script
  • Create a function for this normal script
  • in _ready call the created function
  • there you should see a hint
  • call a func from the created singleton
  • you shouldnt see the func hint

Minimal reproduction project:

N/A

@nonunknown nonunknown changed the title Singletons doesnt show funcs label like inner functions Calling a Singleton's func doesnt show func hint May 10, 2021
@Calinou Calinou added this to the 4.0 milestone May 10, 2021
@Calinou Calinou changed the title Calling a Singleton's func doesnt show func hint Calling a Singleton's func doesn't show autocompletion May 10, 2021
@Calinou Calinou changed the title Calling a Singleton's func doesn't show autocompletion Calling a singleton function doesn't show autocompletion in the editor May 10, 2021
@Calinou Calinou modified the milestones: 4.0, 3.4 May 10, 2021
@Calinou
Copy link
Member

Calinou commented May 10, 2021

In 3.x, the script editor completion doesn't work if you have an error in your script. Fix the error first and autocompletion should appear again. (This is no longer a restriction in master, but this is because the GDScript parser was rewritten from scratch.)

You can increase Idle Parse Delay in the Editor Settings to make the editor wait longer before checking for errors.

@nonunknown
Copy link
Contributor Author

yeah, I've increased, but still the hint doesnt appear. Also this is sure not a regression because I remember this happening on earlier versions of the engine!

@JestemStefan
Copy link
Contributor

JestemStefan commented May 14, 2021

I can confirm that there is no hint for scripts in Autoload. Example:
obraz

But for built-in classes like Engine it works:
obraz

But for normal classes, when calling them from outside of script, it doesn't
obraz

@nonunknown
Copy link
Contributor Author

@Calinou There's another problem to, maybe I should open a proposal for that?

the case is that, what if the user wants to have a scene-only singleton? I mean at scene start he add_autoload_singleton() and at scene finish he calls remove_autoload_singleton(). The problem lies in, when the user call this "temporary" autoload from the scripts inside this scene, isnt possible!

@Calinou
Copy link
Member

Calinou commented May 14, 2021

@Calinou There's another problem to, maybe I should open a proposal for that?

the case is that, what if the user wants to have a scene-only singleton? I mean at scene start he add_autoload_singleton() and at scene finish he calls remove_autoload_singleton(). The problem lies in, when the user call this "temporary" autoload from the scripts inside this scene, isnt possible!

I can't see too many use cases for a scene-only singleton. You can load a .tscn file in the Project Settings' AutoLoad section already. It doesn't have to have a script attached to it, but the global variable reference will still let you access the scene's properties and nodes.

@akien-mga akien-mga modified the milestones: 3.4, 3.5 Nov 8, 2021
@magikmw
Copy link

magikmw commented Nov 29, 2021

@hsandt
Copy link
Contributor

hsandt commented May 1, 2023

On Godot 4.0.2 I now can autocomplete methods called on singletons autoloaded directly via their gd script.
However, if the script is attached to a single-node scene, and that scene is set as autoload singleton, then the autocompletion sometimes doesn't work (Godot is not aware of the type of script attached to that node).

EDIT while writing this comment: after switching to .gd and back to autoload scene, autocompletion now works! I don't know if this is a hack or if Godot just took one minute to properly parse the singleton scene > script.
Anyway, I just added "sometimes" above and kept the rest of my message below in case it happens again.

Will need more testing and see if we can close the issue in both cases, or if there is really a permanent bug sometimes.


I considered strong-typing the node, but to do this you need to name your script with class_name SingletonName.
Unfortunately, when using the exact same name as the autoload singleton, you will get an error

Class "GameManager" hides an autoload singleton.

which makes sense because you know have a redundant declaration (singleton class and singleton instance are not the same thing).

So you now need two names:

class_name MySingletonClass

and in autoload definition, you associate the Singleton.tscn to some name MySingleton or MySingletonInstance and cast MySingletonInstance to MySingletonClass to enable auto-complete, but it's not great.

@HolonProduction
Copy link
Member

Still valid in 4.x (completing the method does work, but the property hint is missing)

@Loufe
Copy link

Loufe commented Mar 27, 2024

This is so bizarre. I wish it were consistent, but it's not.
In my photos below, all functions in the "Omni" singleton had function parameter hints working, yet none worked for the "DTools" singleton. I changed something in "DTools" and reloaded, now neither of them. I have no idea.

NOT WORKING
image
image

WORKING
image
image

image

If anyone could debug this it would be much appreciated, it's very frustrating and sounds like there are a multitude of issues regarding this problem.

To be clear, like @hsandt mentioned, it seems truly random as before my reboot, one of two worked, yet they were identically configured. After, neither did, despite nothing changing whatsoever in the configuration of Omni. However, as @HolonProduction mentions, the autocomplete for the method works, and as you can see in the first two examples below, the parameter count info isn't lost.

For reference, I'm on this commit of the editor in Windows:
image

and experience the same intermittency in the newest "refresh" flatpak on Ubutu/Wayland.

Qu'est-ce que t'en penses, @Calinou ?

@HolonProduction
Copy link
Member

HolonProduction commented Mar 29, 2024

As you might have seen, I submitted I fix, that I believe fixes the issue. Although I did not get inconsistent random behavior, but I could imagine that there are some situations, in which the type of the autoload might be resolved as class because of some caching mechanics 🤷

If you have the capabilities, to compile the engine yourself, could you try applying my fix and tell us how it went?

If not, please try a recent dev built, as #87278 might have an influence as well

@HolonProduction
Copy link
Member

Also, the code that you showed, is it inside of either Omni or DTools?

@KoBeWi KoBeWi modified the milestones: 3.5, 3.x Apr 23, 2024
@MayniYT
Copy link

MayniYT commented Jun 16, 2024

I'm wondering if this problem will be solved? In version 4.2.2 there is still this problem

image
image

@HolonProduction
Copy link
Member

As long as you stick with GDScript, #87278 should have fixed it for 4.3. Feel free to try it in the recent beta.

@akien-mga akien-mga modified the milestones: 3.x, 4.3 Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants