How to replace all references to a resource via plugin?

Godot Version

4.2

Question

I want to make a texture packer that runs as an editor plugin, and that automatically replaces all textures that are packed into the new texture with AtlasTextures referencing the new texture.

My first thought was to try to replace textures by stealing their UIDs and using them for AtlasTextures, but that doesn’t work. In the Godot Editor Filesystem, you can open a menu which shows the owners of the resource. Is there any way to get the list of a resource’s owners in a plugin, then replace the references to the resource with a different resource?

tl;dr: I want to replace all references to a resource with references to a different resource.

Godot already has this behavior built-in. You can select multiple image files and, in the Import tab, select Import As TextureAtlas. You’ll have to set an Atlas File and click Reimport and it will do that.

But how can I do this via code in a plugin?

I don’t know, here’s how the TextureAtlas importer does it godot/editor/import/resource_importer_texture_atlas.cpp at master · godotengine/godot · GitHub

Huh… so, the functionality I want to implement is already kinda built in, just badly documented and also kind of confusing?

Weird. Wonder if I should still start making my own…