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

Automplete breaks when using @onready paired with get_node() #73164

Closed
BlackDragonBE opened this issue Feb 12, 2023 · 4 comments · Fixed by #79386
Closed

Automplete breaks when using @onready paired with get_node() #73164

BlackDragonBE opened this issue Feb 12, 2023 · 4 comments · Fixed by #79386

Comments

@BlackDragonBE
Copy link

BlackDragonBE commented Feb 12, 2023

Godot version

4.0 rc1

System information

Windows 11, GTX 1080Ti, Vulkan

Issue description

Automplete can't find any variables and methods on custom classes when the nodes are loaded with @onready:

simple_rotate.gd:

extends Node2D
class_name SimpleRotate

@export var shouldRotate : bool = true

machine.gd:

@onready var wheel1 : SimpleRotate = $Wheel

func start_motor():
	wheel1.sho... # Doesn't autocomplete, it can't find shouldRotate 

If I add another cast like below, autocomplete does work:
machine.gd:

@onready var wheel1 : SimpleRotate = $Wheel as SimpleRotate

func start_motor():
	wheel1.shouldRotate = true # Autocomplete works

To make things even weirder, it does work if I make Wheel into a unique name and access it using %:
machine.gd:

@onready var wheel1 : SimpleRotate = $"%Wheel"

func start_motor():
	wheel1.shouldRotate = true # Autocomplete works

Steps to reproduce

  • Create a script with a class_name
  • Add that script to a node
  • Create another script referencing the node with the type of the script
  • Try to let automcomplete find any methods or variables on the script with the class_name
  • Notice that it fails

Minimal reproduction project

N/A

@BlackDragonBE
Copy link
Author

This is still an issue in rc4. It might seem like a tiny problem, but it's very confusing for GDScript beginners. It's even referenced in the very video that motivated me to switch from Unity to Godot: https://youtu.be/YVjT0OeE4P0?list=PLRTDZBJAg1Np16EGdovtdqAbYd1eh8BN2&t=668

@notKamui
Copy link

notKamui commented Mar 7, 2023

While it is a "tiny" problem, it is still quite frustrating, especially when you work in a team, and you make an effort of documenting your neatly typed API, and you end up with none of its benefits.

As of now, the workaround with the cast still works with the walrus operator (no need to specify the type twice)

@onready var wheel1 := $Wheel as SimpleRotate

Maybe this is a hint towards the origin of the bug

@saierXP
Copy link

saierXP commented Aug 11, 2023

Maybe we can close this and discuss it in this issue

@lamdevhs
Copy link

lamdevhs commented Oct 2, 2023

I have the same issue, but unique names ('%') don't solve the problem in my case:
@onready var foo: ButtonSubClass = %Foo
The autocompletion does not complete anything from ButtonSubClass, only from Button. The walrus trick from @notKamui does provide a temporary fix to the issue though, so that's nice!

My version: v4.1.1.stable.arch_linux

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.

5 participants