Changing assets during OnWillSaveAssets

Hello!

I have an asset database, and I’d like to add certain assets to that database during OnWillSaveAssets. Part of that step is serializing out the databaseId to that asset. However, I’m noticing that I don’t seem to be able to make any changes to the asset at that time - any changes made look to be overwritten by whatever state the asset was in before OnWillSaveAssets was called.

I tried setting the Id value by digging out the desired behaviour, setting it directly, and using EditorUtility.SetDirty(); as well as by creating a serialized object, modifying the property, and using ApplyModifyProperties. Neither worked.

I have a backup plan to just queue a round of modification/save to another tool after OnWillSaveAssets is complete, but I’d rather be able to just edit the asset directly. Is there a special way to tell the asset database that the asset its about to save has changed or is this not possible?

One tactic I’m currently looking into is removing the asset I’m modifying from the returned path list, and then running AssetDatabase.SaveAssets() after I’ve changed and dirtied the asset. This seems to work out but I get a popup from the first call that informs me “Prefab not saved due to OnWillSaveAssets callback.”. I can’t have this popping up every time, and I thought the whole point of passing in that list to SaveAssets is so that you could remove items from it - I seem to be missing something again.

I would still rather be able to just edit the asset before its saved during the initial saveassets call, removing it from the list and calling save again feels less clean and makes me nervous that something could go wrong and we’d miss the save completely.

Hi! Did you ever figure out a way to do this?