Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AssetDatabase.ExtractAsset

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

public static method ExtractAsset(asset: Object, newPath: string): string;
public static string ExtractAsset(Object asset, string newPath);

Parameters

asset The sub-asset to extract.
newPath The file path of the new Asset.

Returns

string An empty string if Unity has successfully extracted the Asset, or an error message if not.

Description

Creates an external Asset from an object (such as a Material) by extracting it from within an imported asset (such as an FBX file).

NOTE: The feature is currently only available for materials embedded in model assets.

All file paths are relative to the project folder. For example: "Assets/Materials/myMaterial.mat".

Method throws ArgumentNullException when the Asset is null and ArgumentException when the file path is null or empty.

#pragma strict
public class Extractor {
	public static function ExtractFromAsset(subAsset: Object, destinationPath: String) {
		var assetPath: String = AssetDatabase.GetAssetPath(subAsset);
		AssetDatabase.ExtractAsset(subAsset, destinationPath);
		AssetDatabase.WriteImportSettingsIfDirty(assetPath);
		AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
	}
}
using UnityEngine;
using UnityEditor;

public class Extractor { public static void ExtractFromAsset(Object subAsset, string destinationPath) { string assetPath = AssetDatabase.GetAssetPath(subAsset);

AssetDatabase.ExtractAsset(subAsset, destinationPath);

AssetDatabase.WriteImportSettingsIfDirty(assetPath); AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } }

Did you find this page useful? Please give it a rating: