How to use export var for file paths in Godot 4

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

i coding a dialogue system maded by devWorm, he uses godot 3, i tried to use export var for take the file json that countains the dialogues.

@export var path_to_file : String

that code, if i print, returns “”, i tried export_dir, export_globaldir, but doen’st work too, then I need the export var for, in each Npc that i instanciate that dialogue system, it could receive a different json file with different dialogues.

I think there is some kind of bug, but I am not sure.

I tried the following and got the same problem:

@export_file("*.gd") var __funcs_file: String

func _ready():

I assign a .gd file in the editor and got an empty string.


After a bit of trying I found the following out:

Assigning the file path from the scene containing the node with the script that exports the variable works.

If I assign the file path in a scene containing the other scene, it doesn’t work.

fraang | 2023-03-21 11:04

:bust_in_silhouette: Reply From: zhyrin

Make sure you actually set the value, also note that exported variables are not set to their values before _ready().

Here are the 4.0 export options: GDScript exports — Godot Engine (stable) documentation in English