Godot Version
4.4
Question
Hey. I’m working on a kind of CMS plugin, allowing me to keep track of resources connected to scenes, and easily create a new resource, along with a new scene, and connect them programmatically. I have made a method that runs when I click there “new resource” button which executes the following code:
EditorInterface.Singleton.OpenSceneFromPath("res://level/rooms/room_template.tscn");
EditorInterface.Singleton.SaveSceneAs("res://level/rooms/scenes/" + filename + ".tscn");
PackedScene scene = ResourceLoader.Load<PackedScene>(EditorInterface.Singleton.GetEditedSceneRoot().SceneFilePath);
RoomResource resource = new RoomResource()
{
Name = name,
FileName = filename,
Texture = texture,
};
resource.Save();
resource.Scene = scene;
This successfully opens a template scene and saves it as a new packed scene at the designated location, but it isn’t properly applied to the resource. It either doesn’t change the value at all (it shows as “empty” in the inspector) or it shows up as “packedscene” and doesn’t allow me to click “open scene”. Here, it has the same path as my newly saved scene, and when attempting to delete the scene, the resource does depend on it.. Strangely, if I manually clear the resource’s scene property and select my new scene, it works as expected.
setting the property before I saved the resource doesn’t have a consistent effect and creating a packed scene with PackedScene.Pack([instantiated template scene]) does the same thing.
I feel like there should be a better way to do this.. what am I doing wrong?