Undo on static variable?

Hi,

This is the situation:
I have an asset in my scene. Whenever I duplicate it, its assets (meshes, mat, etc.) are uniquified. Whenever I delete one of these assets from my scene, I need those unique assets to be deleted also. However, not immediately because I want to retain undo funcionallity.

What I made is a script that stores asset paths and as soon as the EditorApplication.isQuitting event is fired, it deleted those assets from the project. I currently have a singleton patern that creates a HideAndDontSave gameobject in the scene with the monobehaviour component. This stores the list of asset paths (string).

How do I make sure that as soon as I undo the deletion of the asset from the scene, this list is also restored so that the added path is once again removed? I tried making the class static, a monobehaviour, a ScriptableObject, nothing seems to be able to register the Undo of this list properly. Also Undo.RegisterCompleteObjectUndo does not seem to work.

Any idea’s? I’m out of any :frowning:

Kind regards,

Mathijs van Nimwegen

I’m not entirely sure what you’re exactly doing, but it sounds like you might need to add a custom implementation for this.

Undo.undoRedoPerformed could be used for this in a custom inspector, but this wouldn’t work if your Inspector isn’t open when destroying the object. OnDestroy & Awake would then be where you implement this. (or you could force your inspector to open in these methods by selecting the object with "Selection.activeObject = ")

1 Like

I finally figured it our… The list was set to private. Apparently if it is not serialized, the undo function cannot, well, serialize it…
Makes sense now but this was 4 hours just staring at 150 lines of code.
Thanks for your response anyway!

1 Like