Relative paths don't work with load
or ResourceLoader.Load
because contrary to preload
(which is specific to GDScript and deduced at compile time), the former does not have any info from where it runs, and so cannot do a relative path lookup. C# itself doesn't know this either. See https://github.com/godotengine/godot/issues/5999#issuecomment-249435940
I know in GDScript it's possible to still use the path of the script, which then you would append to a relative path to form an absolute path, which works like this:
load(get_script().resource_path.base_dir() + "/relative_path/resource.png")
Which in C# would maybe become:
ResourceLoader.Load<AudioStream>(((Resource)GetScript()).ResourcePath + "/relative_path/resource.png")
You could likely write an extension method to Godot.Object
so that Load
is always available anywhere with relative paths? But ResourceLoader
is a separate class so it cannot do that automatically.
But otherwise you really have to input full paths. Note that it's actually recommended you export resource properties, rather than hardcoding them. If you do this, Godot will automatically reassign the path if you move the asset from the editor.
In GDScript it's more common to hardcode script paths because it is the only way to access other script classes (unless they use class_name
), but C# classes are all named so it doesn't have this problem.