Make sprite behave as if new

Hi! I am creating an import script which uses a template sprite. It first opens the template sprite, then it reads from the input file and uses that data to draws on the template sprite, inside particular slices. When this is finished I don’t want the user to accidentally save over the template sprite. I would like it to behave like a new sprite - it should have a name like “Sprite-0001” and attempting to do “File → Save” should open a save dialog rather than immediately overwriting the file. Is there any way to do this? I have tried:

  1. Change sprite.filename to an empty string. This does prevent saving over the template, but it is undesirable because it makes “File → Save” produce an error about a bad filename.
  2. Copy the sprite using local sprite2 = Sprite(sprite1). This partially works. The new sprite still has the name of the template. “File → Save” doesn’t immediately save over it, but it does still suggest to save over it with the same name in the same directory. Additionally, the copy has lost all its slices, although I imagine I could work around this by copying them by script.

The only way I can really see to get the effect I want is to load the template, create a brand new empty sprite, then copy across all the layers, frames, cels and slices, then close the template again. Is there a better way?

Just read this post and had to double check my template plugin that I just made, and sure enough, I see the same issue as you mention with the whole name remaining the same. which could lead to replacement if you’re not careful.

I’d be really curious to find out if there is a solution to this as well.

So it turns out you sort of can do this. If you do the duplication via the Sprite(original) and then set the filename of that new sprite to something new (either an empty string, or something more typical like ‘Sprite-0001’). This will be enough to stop the user accidentally saving over the original template.

NOTE: However I have observed that the filename change does not update the sprite tab in-editor right away (at least not in my case), but hitting F5 to refresh, or opening a file save/open dialog does update this (trying to force that refresh in my script at the moment but doesn’t seem to be doing anything).