Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

AssetDatabase.ForceReserializeAssets

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static void ForceReserializeAssets();

Description

Loads, upgrades, and writes back to disk every asset in the project.

When Unity loads old data from an asset or scene file, it upgrades the data in memory, but doesn't write it back to disk until something changes the object. Use this method to load, upgrade, and write back assets in a controlled way, without changing them by hand. This avoids upgrades getting mixed in with deliberate changes, which helps in projects that use version control.

Only call this method from a direct user action, such as a menu item. Don't call it from a Unity callback such as OnEnable, because a scene might be changing at that time. If you do, Unity throws an exception. This overload reserializes every asset in the project. To choose which assets to reserialize, use the overload that takes assetPaths.

using UnityEditor;
using UnityEngine;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Force Reserialize Assets Example")] static void UpdateGroundMaterials() { for (var i = 0; i < 10; i++) { var matPath = $"Assets/Materials/GroundMaterial{i}.mat"; var mat = (Material)AssetDatabase.LoadMainAssetAtPath(matPath); AssetImporter.GetAtPath(matPath).SetAssetBundleNameAndVariant("GroundBundle", ""); mat.shader = Shader.Find("Standard"); mat.color = Color.white; mat.mainTexture = (Texture)AssetDatabase.LoadMainAssetAtPath($"Assets/Textures/GroundTexture{i}.jpg"); } AssetDatabase.ForceReserializeAssets();

} }

Declaration

public static void ForceReserializeAssets(IEnumerable<string> assetPaths, ForceReserializeAssetsOptions options);

Parameters

Parameter Description
assetPaths The project-relative paths of the assets to reserialize.
options Whether to reserialize the assets, their .meta files, or both. The default value reserializes both.

Description

Loads, upgrades, and writes back to disk the specified assets, their .meta files, or both.

When Unity loads old data from an asset or scene file, it upgrades the data in memory, but doesn't write it back to disk until something changes the object. Use this method to load, upgrade, and write back assets in a controlled way, without changing them by hand. This avoids upgrades getting mixed in with deliberate changes, which helps in projects that use version control.

Only call this method from a direct user action, such as a menu item. Don't call it from a Unity callback such as OnEnable, because a scene might be changing at that time. If you do, Unity throws an exception.