- Home /
AssetDatabase.SaveAssets is not saving changes
I'm trying to gain an understanding of how AssetDatabase works by loading a Texture2D with LoadAssetAtPath, changing a value, and saving the change back. The loading part is working just fine, the changing part is working just fine, but the saving part isn't working at all. Here is the relevant code:
private void OnGUI()
{
EditorGUILayout.BeginVertical();
if (icon != null)
{
EditorGUILayout.LabelField(icon.name);
icon.anisoLevel = (int)EditorGUILayout.Slider(icon.anisoLevel, 0, 15);
if (EditorUtility.IsDirty(icon.GetInstanceID()))
{
EditorGUILayout.LabelField("Is dirty!");
AssetDatabase.SaveAssets();
}
}
else EditorGUILayout.LabelField("Asset not found");
EditorGUILayout.EndVertical();
}
When I move the slider the "Is Dirty!" message pops up, but then never goes away and when looking at the asset on disk in the inspector the property is still the default value, 1. I have tried putting in EditorUtility.SetDirty, but it didn't do anything. What am I not understanding here? How do I get this to save the change to disk?
Edit: I should add that this is being done in an EditorWindow class, in case that matters.
Answer by Languard · Apr 20, 2020 at 04:57 PM
I received an answer over in the forums, so I thought I would copy it over here.
Basically, I was trying to change an imported asset setting. You can do that, but it's a completely different process. The process I'm using here only works for things like prefabs and other intrinsic, non-imported assets.
Your answer
![](https://koobas.hobune.stream/wayback/20220612231532im_/https://answers.unity.com/themes/thub/images/avi.jpg)