# ScriptedImporter

> Abstract base class for custom Asset importers.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.AssetImporters](/engine/6000.3/script-reference/unityeditor/assetimporters.md)
* **Assembly:** UnityEditor
* **Inherits from:** [AssetImporter](/engine/6000.3/script-reference/unityeditor/assetimporter.md)

```csharp
public abstract class ScriptedImporter : AssetImporter
```

## Remarks

Scripted importers are scripts that are associated with specific file extensions. They are invoked by Unity's Asset pipeline to convert the contents of associated files into Assets.

Use the [ScriptedImporterAttribute](/engine/6000.3/script-reference/unityeditor/assetimporters/scriptedimporterattribute.md) class to register custom importers with the Asset pipeline.

The C# fields of a ScriptedImporter are serialized, exactly like fields on a MonoBehaviour. See [Script Serialization](/engine/6000.3/manual/scripting/compilation-and-code-reload/script-serialization.md) for details. You can see these properties in the Inspector and use them to control the behaviour of the importer for each asset. To programmatically access the value of an asset's properties, use [AssetImporter.GetAtPath](/engine/6000.3/script-reference/unityeditor/assetimporter/getatpath.md) and type cast the return value to the correct class derived from ScriptedImporter. After changing values, trigger a fresh import by calling [EditorUtility.SetDirty](/engine/6000.3/script-reference/unityeditor/editorutility/setdirty.md) and then [AssetImporter.SaveAndReimport()](/engine/6000.3/script-reference/unityeditor/assetimporter/saveandreimport.md).

## Examples

```csharp
using UnityEngine;
using UnityEditor.AssetImporters;
using System.IO;

[ScriptedImporter(1, "cube")]
public class CubeImporter : ScriptedImporter
{
    public float m_Scale = 1;

    public override void OnImportAsset(AssetImportContext ctx)
    {
        var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
        var position = JsonUtility.FromJson<Vector3>(File.ReadAllText(ctx.assetPath));

        cube.transform.position = position;
        cube.transform.localScale = new Vector3(m_Scale, m_Scale, m_Scale);

        // 'cube' is a GameObject and will be automatically converted into a Prefab
        // (Only the 'Main Asset' is eligible to become a Prefab.)
        ctx.AddObjectToAsset("main obj", cube);
        ctx.SetMainObject(cube);

        var material = new Material(Shader.Find("Standard"));
        material.color = Color.red;

        // Assets must be assigned a unique identifier string consistent across imports
        ctx.AddObjectToAsset("my Material", material);

        // Assets that are not passed into the context as import outputs must be destroyed
        var tempMesh = new Mesh();
        DestroyImmediate(tempMesh);
    }
}
```

## Methods

| Method                                                                                                                                              | Description                                                                                                                                                              |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [GatherDependenciesFromSourceFile](/engine/6000.3/script-reference/unityeditor/assetimporters/scriptedimporter/gatherdependenciesfromsourcefile.md) | A static callback that you can implement to set up artifact dependencies to other Assets, and optimize the order your assets are imported.                               |
| [OnImportAsset](/engine/6000.3/script-reference/unityeditor/assetimporters/scriptedimporter/onimportasset.md)                                       | This method must be overriden by the derived class and is called by the Asset pipeline to import files.                                                                  |
| [OnValidate](/engine/6000.3/script-reference/unityeditor/assetimporters/scriptedimporter/onvalidate.md)                                             | This function is called when the importer is loaded or a value is changed in the Inspector.                                                                              |
| [Reset](/engine/6000.3/script-reference/unityeditor/assetimporters/scriptedimporter/reset.md)                                                       | Reset to default values.                                                                                                                                                 |
| [SupportsRemappedAssetType](/engine/6000.3/script-reference/unityeditor/assetimporters/scriptedimporter/supportsremappedassettype.md)               | Override this method if your [ScriptedImporter](/engine/6000.3/script-reference/unityeditor/assetimporters/scriptedimporter.md) supports remapping specific asset types. |

## Inheritance

**Inherited Members:**

* [AssetImporter.GetImportLog(string)](/engine/6000.3/script-reference/unityeditor/assetimporter/getimportlog.md)
* [AssetImporter.SetAssetBundleNameAndVariant(string, string)](/engine/6000.3/script-reference/unityeditor/assetimporter/setassetbundlenameandvariant.md)
* [AssetImporter.GetAtPath(string)](/engine/6000.3/script-reference/unityeditor/assetimporter/getatpath.md)
* [AssetImporter.SaveAndReimport()](/engine/6000.3/script-reference/unityeditor/assetimporter/saveandreimport.md)
* [AssetImporter.AddRemap(SourceAssetIdentifier, Object)](/engine/6000.3/script-reference/unityeditor/assetimporter/addremap.md)
* [AssetImporter.RemoveRemap(SourceAssetIdentifier)](/engine/6000.3/script-reference/unityeditor/assetimporter/removeremap.md)
* [AssetImporter.GetExternalObjectMap()](/engine/6000.3/script-reference/unityeditor/assetimporter/getexternalobjectmap.md)
* [AssetImporter.assetPath](/engine/6000.3/script-reference/unityeditor/assetimporter/assetpath.md)
* [AssetImporter.importSettingsMissing](/engine/6000.3/script-reference/unityeditor/assetimporter/importsettingsmissing.md)
* [AssetImporter.userData](/engine/6000.3/script-reference/unityeditor/assetimporter/userdata.md)
* [AssetImporter.assetBundleName](/engine/6000.3/script-reference/unityeditor/assetimporter/assetbundlename.md)
* [AssetImporter.assetBundleVariant](/engine/6000.3/script-reference/unityeditor/assetimporter/assetbundlevariant.md)
* [Object.GetInstanceID()](/engine/6000.3/script-reference/unityengine/object/getinstanceid.md)
* [Object.GetHashCode()](/engine/6000.3/script-reference/unityengine/object/gethashcode.md)
* [Object.InstantiateAsync\<T>(T)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform, Vector3, Quaternion)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, CancellationToken)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, InstantiateParameters, CancellationToken)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, InstantiateParameters, CancellationToken)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, InstantiateParameters, CancellationToken)](/engine/6000.3/script-reference/unityengine/object/instantiateasync.md)
* [Object.Instantiate(Object, Vector3, Quaternion)](/engine/6000.3/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion\))
* [Object.Instantiate(Object, Vector3, Quaternion, Transform)](/engine/6000.3/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion-transform\))
* [Object.Instantiate(Object)](/engine/6000.3/script-reference/unityengine/object/instantiate.md#instantiate\(object\))
* [Object.Instantiate(Object, Scene)](/engine/6000.3/script-reference/unityengine/object/instantiate.md#instantiate\(object-scene\))
* [Object.Instantiate\<T>(T, InstantiateParameters)](/engine/6000.3/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, InstantiateParameters)](/engine/6000.3/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate(Object, Transform)](/engine/6000.3/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform\))
* [Object.Instantiate(Object, Transform, bool)](/engine/6000.3/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform-bool\))
* [Object.Instantiate\<T>(T)](/engine/6000.3/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion)](/engine/6000.3/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, Transform)](/engine/6000.3/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform)](/engine/6000.3/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform, bool)](/engine/6000.3/script-reference/unityengine/object/instantiate.md)
* [Object.Destroy(Object, float)](/engine/6000.3/script-reference/unityengine/object/destroy.md)
* [Object.DestroyImmediate(Object, bool)](/engine/6000.3/script-reference/unityengine/object/destroyimmediate.md)
* [Object.FindObjectsByType(Type, FindObjectsSortMode)](/engine/6000.3/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectssortmode\))
* [Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)](/engine/6000.3/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectsinactive-findobjectssortmode\))
* [Object.DontDestroyOnLoad(Object)](/engine/6000.3/script-reference/unityengine/object/dontdestroyonload.md)
* [Object.FindObjectsByType\<T>(FindObjectsSortMode)](/engine/6000.3/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectssortmode\))
* [Object.FindObjectsByType\<T>(FindObjectsInactive, FindObjectsSortMode)](/engine/6000.3/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectsinactive-findobjectssortmode\))
* [Object.FindFirstObjectByType\<T>()](/engine/6000.3/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytypet\(\))
* [Object.FindAnyObjectByType\<T>()](/engine/6000.3/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(\))
* [Object.FindFirstObjectByType\<T>(FindObjectsInactive)](/engine/6000.3/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytypet\(findobjectsinactive\))
* [Object.FindAnyObjectByType\<T>(FindObjectsInactive)](/engine/6000.3/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(findobjectsinactive\))
* [Object.FindFirstObjectByType(Type)](/engine/6000.3/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytype\(type\))
* [Object.FindAnyObjectByType(Type)](/engine/6000.3/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type\))
* [Object.FindFirstObjectByType(Type, FindObjectsInactive)](/engine/6000.3/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytype\(type-findobjectsinactive\))
* [Object.FindAnyObjectByType(Type, FindObjectsInactive)](/engine/6000.3/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type-findobjectsinactive\))
* [Object.ToString()](/engine/6000.3/script-reference/unityengine/object/tostring.md)
* [Object.name](/engine/6000.3/script-reference/unityengine/object/name.md)
* [Object.hideFlags](/engine/6000.3/script-reference/unityengine/object/hideflags.md)

### Operators

| Operator                                                                           | Description                                                             |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [operator ==](/engine/6000.3/script-reference/unityengine/object/op-equality.md)   | Compares two object references to see if they refer to the same object. |
| [bool](/engine/6000.3/script-reference/unityengine/object/op-implicit.md)          | Determines whether the object exists.                                   |
| [operator !=](/engine/6000.3/script-reference/unityengine/object/op-inequality.md) | Compares if two objects refer to a different object.                    |
