auto complete works in func _ready. It does not work in func _process. why?

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

var node:RayCast = null

func _ready():
	node = get_node("RayCast")
	print(node.get_class())
	
func _process(delta):
	node.is_colliding()

A type is required to make auto complete work in a func process.

:bust_in_silhouette: Reply From: Jowan-Spooner

We should remember how auto-completion works. It has to suggest completely different things for each different type. In the _ready() function you assign the node variable and godot internally already has a look at the node you’re trying to get. So it knows it’s type and knows what functions it has. But in your _process() function there is no such way for godot to know what type your variable will have and thus it cannot do auto-completion. There are several ways to get it working, like the one you already have done. You could also do

func _process(delta):
    (node as RayCast).is_colliding()

that is useful if your node variable is going to have different types in your game but at this specific position it only should have a special one. This should also work with self made class_names, but idk.

Well, hope it helps. Good luck, Jowan

Thank you
I knew that the presence or absence of substitution had an effect.

bgegg | 2019-06-17 09:38

That doesn’t make sense to me. The OP explicitly declares node to be a class member of type RayCast, so at no point it should have any other type except for maybe inherited types. So at the very least auto complete should know it’s a RayCast type and offer proper auto coplete without (node as Raycast) inside _process. Am I mistaken?

omggomb | 2019-06-17 10:20

yes i missed in code.
this is correct.sorry.

extends Camera

var node = null

func _ready():
    node = get_node("RayCast")
    print(node.get_class())

func _process(delta):
    node.is_colliding()

bgegg | 2019-06-17 11:23