Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

BuildAssetBundleOptions.DisableWriteTypeTree

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

Description

Omits type information from the AssetBundle.

This flag is useful for AssetBundles that are included in Player builds and are rebuilt for every new Player release. However, before using this flag, it is critical to fully understand the compatibility and redistribution implications of removing TypeTrees.

By default when this flag isn't specified, each SerializedFile inside an AssetBundle contains the TypeTree information for all types used in that file.

TypeTrees enable Unity to:

  • Load content that was built with earlier versions of Unity or with different script versions.
  • Load AssetBundles in the Editor.

When this flag is specified, only the hash of each TypeTree is recorded in the SerializedFile headers, not the entire TypeTree definition.

Example:

An AssetBundle includes instances of a MonoBehaviour-derived class with two fields: a string A followed by an integer B. The TypeTree records the order, types and names of the fields so that the binary presentation of each serialized object of that type can be interpreted properly.

If the class definition changes to include a float C first, followed by integer B and string A, then the TypeTree inside the AssetBundle ensures that new builds of the Player can still load it. It recovers the values of the A and B fields even though they don't match the current definition of that class.

Advantages of using DisableWriteTypeTree:

Omitting TypeTrees reduces AssetBundle size, which can be significant for projects with many small AssetBundles or complex scripting types containing numerous fields or deeply nested structs. Therefore, this flag can be a useful optimization in cases where you know that you will always rebuild and redistribute all AssetBundles any time that you rebuild the Player.

Important Considerations:

AssetBundles built without TypeTrees have strict compatibility requirements:

  • They can only be loaded by Players built with exactly the same types. Unity verifies this by comparing TypeTree hashes at load time, and the load fails if any mismatch is detected.
  • They cannot be loaded in the Editor.
  • Tools like binary2text and UnityDataTools cannot view the serialized data.