Version: 2022.3
LanguageEnglish
  • C#

AudioImporter

class in UnityEditor

/

Inherits from:AssetImporter

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

Use this class to modify AudioClip import settings from editor scripts.

Use these settings to ensure all or a subset of your audio files have the same import settings. You can also edit these settings in the Audio Clip Inspector.

Additional resources: AudioClip

// This script adds a new menu item to the Unity Editor. Select the menu item to change the settings of and reimport audio from a certain folder. 

using UnityEditor; using UnityEngine;

public class AudioImporterExample { // Creates a new menu item in Unity Editor. [MenuItem("Tools/Reimport sounds with new settings")] public static void SetAllToAmbisonic() { // Put the audio that you want to change in this directory. string folderPath = "Assets/Sounds";

// Find all AudioClip assets in the specified folder. string[] guids = AssetDatabase.FindAssets("t:AudioClip", new[] { folderPath });

foreach (string guid in guids) { // Get the paths to the audio clips. string assetPath = AssetDatabase.GUIDToAssetPath(guid);

// Get the AudioImporter for this audio clip. AudioImporter importer = AssetImporter.GetAtPath(assetPath) as AudioImporter; if (importer != null) { // Change the importer settings. importer.ambisonic = true; importer.loadInBackground = true; importer.forceToMono = false; // Reimport the asset to apply changes. AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); Debug.Log($"Changed '{assetPath}' settings."); } } } }

Properties

ambisonicEnable this property to treat the audio clip as ambisonic.
defaultSampleSettingsThe default sample settings for the AudioClip importer.
forceToMonoForce audioclips to mono sound type, so all audio plays through a single channel.
loadInBackgroundCorresponding to the "Load In Background" flag in the AudioClip inspector, when this flag is set, the loading of the clip will happen delayed without blocking the main thread.

Public Methods

ClearSampleSettingOverrideClears the sample settings override for the given platform.
ContainsSampleSettingsOverrideReturns whether the sample settings for a specified build target are currently overridden.
GetOverrideSampleSettingsReturn the current override settings for the given platform.
SetOverrideSampleSettingsSets the override sample settings for the given platform.

Inherited Members

Properties

assetBundleNameGet or set the AssetBundle name.
assetBundleVariantGet or set the AssetBundle variant.
assetPathThe path name of the asset for this importer. (Read Only)
importSettingsMissingThe value is true when no meta file is provided with the imported asset.
userDataGet or set any user data.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

AddRemapMap a sub-asset from an imported asset (such as an FBX file) to an external Asset of the same type.
GetExternalObjectMapGets a copy of the external object map used by the AssetImporter.
RemoveRemapRemoves an item from the map of external objects.
SaveAndReimportSave asset importer settings if asset importer is dirty.
SetAssetBundleNameAndVariantSet the AssetBundle name and variant.
SupportsRemappedAssetTypeChecks if the AssetImporter supports remapping the given asset type.
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.

Static Methods

GetAtPathRetrieves the asset importer for the asset at path.
GetImportLogRetrieves logs generated during the import of the asset at path.
DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
FindObjectsOfTypeGets a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.
InstantiateAsyncCaptures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.