Godot 4.2.1: missing autocomplete - file_path vs scene_file_path

image

When following along, noticed the body.file_path does not appear on the list and instead tries to make you use scene_file_path.
I assumed this had just been updated but couldn’t get it to work and, and presented the below error when touching the landing pad:
image

When trying to avoid the automcomplete and manually typing as body.file_path it worked just fine however.

I can’t seem to find any info on either in the Godot docs so was wondering if anyone could shed any light on the difference between the two, why Godot no longer seems to see file_path in the autocomplete, and ideally what this error message actually means as I cannot work it out on this occassion!

It looks like you’re doing Project Boost, so maybe Bram will mention this later in the course. For now, just know that in GDscript, when something unexpectedly doesn’t show up in intellisense, it doesn’t necessarily mean that thing isn’t there.

Godot is a little unintuitive when it comes to intellisense, and the main reason for this (that I’m aware of) is that GDscript is not a strongly-typed language. When you declare a variable and you don’t restrict it to one datatype, intellisense won’t display anything that potentially doesn’t exist in that datatype. As an example:

  • @onready var player = $Player has basic intellisense
  • @onready var player: RigidBody3D = $Player will have more specific intellisense, since Godot knows this variable will only ever contain a RigidBody3D

This may not be what’s happening in your specific case (I haven’t done this course yet), but it’s still something to bear in mind because it’s definitely not obvious - as it is, I learned about this from reddit, not the docs =P

Since you got it to work in the end by ignoring intellisense and typing file_path anyway, I’m pretty sure this error message is just the result of incorrectly using scene_file_path instead for whatever it was you were trying to retrieve, so nothing to worry about =)

1 Like

It doesn’t appear because Godot doesn’t know it exists, it will check at runtime, when the code is executed. It may lead to crashes or error if badly implemented (typo, delete the variable/function), that’s why it’s better to strong type and use classes when communicating between scenes so the autocompletion can help and precompilation will display an error that what you’re doing will not work.
The body parameter is of type Node, but maybe it’s another thing like a RigidBody, which has more properties than a simple Node. You can cast it with

var rb = body as RigidBody

then check if rb is not null before proceding with

if(is_instance_valid(rb)):

code here

In this case, our script isn’t its own class but you can still check with

if(“file_path” in body):

print(body.file_path)

1 Like

Hi ashcon,

Maybe you did find it out already but for all the people looking for more info about this.

What is refereed to is actually the name you gave the variable on the LandingPad.gd script.
Screenshot 2024-02-22 062943

For example I have called my variable next_level_file so I refer to body.next_level_file that can be fount in the body of the LandingPad.
Screenshot 2024-02-22 063051

Hope this helps and answers the question.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms