# ExtractAsset(Object, string)

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

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static string ExtractAsset(Object asset, string newPath)
```

### Parameters

**** (\[Object]\(/engine/6000.7/script-reference/unityengine/object)): The sub-asset to extract.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The file path of the new Asset.

### Returns

| Type                                                           | Description                                                                                |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | An empty string if Unity has successfully extracted the Asset, or an error message if not. |

### Remarks

**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*.

### Examples

```csharp
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);
    }
}
```
