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

Godot 4 class_name autocomplete not consistently working when attaching to parent class node despite using static type declarations and only works if "as" keyword is used #82592

Closed
mmmmmmmmmmmmmmmmmmmdonuts opened this issue Sep 30, 2023 · 6 comments · Fixed by #79386

Comments

@mmmmmmmmmmmmmmmmmmmdonuts

Godot version

4.1.1

System information

windows 11

Issue description

When registering a type with class_name and using that class name to declare a variable in code only, autocomplete works as expected anywhere in other nodes/scenes. However, if making a custom scene node that extends a script with the class_name, if that custom scene is instantiated in a different scene, even if the type is specified, it only shows the parent node's functions and not any of the extended functionality. I have made a basic project showing the issue

Steps to reproduce

I have made a very simple project showing the issue. https://github.com/mmmmmmmmmmmmmmmmmmmdonuts/godot_4_autocomplete_issue essentially, the extended Node scene will only show the custom function when both the type is specified as well as the type afterwards following "as"
e.g. @onready var my_class_4: MyClass = $MyClass4 as MyClass

Minimal reproduction project

https://github.com/mmmmmmmmmmmmmmmmmmmdonuts/godot_4_autocomplete_issue

@ShadowSFX
Copy link

ShadowSFX commented Oct 6, 2023

I can confirm this. It completely ignores the type unless there is an "as" keyword.

Basic health component class:

extends Node
class_name HealthComponent

signal died

@export var max_health: float = 10
var current_health

func _ready():
	current_health = max_health

func damage(damage_amount: float):
	current_health = max(current_health - damage_amount, 0)
	Callable(check_death).call_deferred()

func check_death():
	if current_health == 0:
		died.emit()
		owner.queue_free()

and using it in another script like this:

  1. @onready var health_component: HealthComponent = $HealthComponent (this does NOT offer autocomplete)
  2. @onready var health_component: HealthComponent = $HealthComponent as HealthComponent (this offers autocomplete)
  3. @onready var health_component = $HealthComponent as HealthComponent (this offers autocomplete)

using export like this:

@export var health_component: HealthComponent does offer autocomplete.

but option 1 should offer autocomplete.

@Calinou
Copy link
Member

Calinou commented Oct 6, 2023

PS: Code blocks should use triple backticks like this (with an optional language name for syntax highlighting):

```gdscript
code here
```

I edited your post accordingly, but remember to do this in the future 🙂

@AnidemDex
Copy link

AnidemDex commented Oct 6, 2023

Isn't this related to an older issue about editor suggestions/autocompletion not being consistent?

Edit: Here, found the issue #42005

@ShadowSFX
Copy link

PS: Code blocks should use triple backticks like this (with an optional language name for syntax highlighting):

gdscript code here

I edited your post accordingly, but remember to do this in the future 🙂

ooh! thank you very much!

I really hope this gets some attention to get fixed ><

@TestSubject06
Copy link
Contributor

TestSubject06 commented Oct 9, 2023

I have nothing to add, other than that this just hit me and cost a little bit of time. Using Godot 4.1.1

image

+1

@HolonProduction
Copy link
Contributor

Duplicate of #73164 and #73638

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.

7 participants