Sturdy Path is a simple Godot addon that provides a way to reference a scene or resource by path, in a manner that won't break when moving files around within the project. This is accomplished by keeping track of the target file's uid://
path, which is invariant of the file's location within the project.
- Copy the
addons/mpewsey.sturdypath
directory from this repository into theaddons
folder of your Godot project. - Build your Godot project solution, so that the newly incorporated C# addon scripts are compiled.
- Enable the addon by going to
Project > Project Settings
and clicking the enable checkbox next to the plugin.
using MPewsey.SturdyPath;
public partial class BattleEffect : Resource
{
// Create an exported SturdyPathRef property for the scene or resource you wish to reference by path.
[Export] public SturdyPathRef VfxScenePath { get; set; }
// Use the SturdyPathRef.Load method to load the resource for use per typical Godot usage patterns.
public void SpawnVfx(Node parent)
{
var scene = VfxScenePath.Load<PackedScene>();
var vfx = scene.Instantiate();
parent.AddChild(vfx);
}
}