custom properties and functions from other nodes are not showing in suggestion

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cgvirus

Player node has a script:

extends Area2D
var health
func run():
    pass

If I call the node in “main” with

$Player.

should give us in suggestion:

$Player.health or $Player.run()

Script editor doesn’t show suggestion for health or run(). Also can’t go to the code with ctrl+click in Godot 4.

Is it a bug? Thanks!

:bust_in_silhouette: Reply From: spaceyjase
$Player

Is the type of the node; e.g. Area2D. And while health and run() will work at runtime (thanks dynamic languages!), godot doesn’t know unless given a type (it sees only Area2D).

If you do this:

class_name Player
extends Area2D
var health
func run():
    pass

and:

($Player as Player).

The editor will auto complete.

Now it’s working! Thanks!

cgvirus | 2023-04-06 21:21

Hi, it seems like Godot 3 script editor can do it without assigning classes. Do you know what might have changed this behavior in Godot 4?

cgvirus | 2023-04-13 00:07

:bust_in_silhouette: Reply From: cgvirus

Just adding for future

Thanks to spaceyjase’s answer. it is due to dynamic type scripting.
Although Godot supports static typing and that is more favorable IMHO. I have found a good doc in Godot doc lately. For reference:

Static Typing variable casting

So for my problem this worked nicely.
Player class:

extends Area2D
class_name Player

var health
func run():
    pass

Main class:

@onready var my_player := $Player as Player