0 votes
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.

in Engine by (203 points)

1 Answer

0 votes
Best answer

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

by (864 points)
selected by

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

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?

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()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.