GDscript: Load res-files with relative path, how?

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

Hi…,

my fileSystem looks like this:

res://
level
  player
    player_script.gd
    media
       jump_sound.wav

so the absolute path for my sound file is "res://level/player/media/jump_sound.wav".

In player_script.gd I would like to load jump_sound.wav with a relative path like this (because, when I move the folder player, the script is broken with an absolute path):

var jump_sound = load("media/jump_sound.wav")  # doesn't work

Is there a way for relative load paths in GDscript?

Thanks

Mike

:bust_in_silhouette: Reply From: rossunger

if you use “preload” instead of “load” that should work

Hi rossunger, preload() works, great, thank you

MikeMikeMike | 2022-12-19 08:00