Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


IsForeignAsset

Checks whether an asset object is a foreign asset, created outside Unity.
Read time 2 minutesLast updated 3 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

IsForeignAsset(Object)

Checks whether an asset object is a foreign asset, created outside Unity.
public static bool IsForeignAsset(Object obj)

Parameters

The asset object to check.

Returns

Type

Description

boolTrue if the asset is a foreign asset. Otherwise, false.

Remarks

A foreign asset is an asset that wasn't created in Unity, for example a .png texture file. During import, Unity creates a serialized representation of a foreign asset in the
Library
folder of the project. This happens when you first add the asset, when it changes outside Unity, and when you change its import settings. An asset that Unity creates, such as a material, is a native asset. For more information, refer to Native asset importers reference and AssetDatabase.IsNativeAsset.

Examples

using UnityEditor;using UnityEngine;public class AssetDatabaseExamples : MonoBehaviour{ [MenuItem("AssetDatabase/Find Foreign Assets")] static void FindForeignAssets() { //Find all foreign assets foreach (var guid in AssetDatabase.FindAssets("",new []{"Assets"})) { var path = AssetDatabase.GUIDToAssetPath(guid); var asset = AssetDatabase.LoadMainAssetAtPath(path); var assetIsForeign = AssetDatabase.IsForeignAsset(asset); if(assetIsForeign) Debug.Log(asset); } }}

IsForeignAsset(EntityId)

Checks whether the asset with the specified EntityId is a foreign asset, created outside Unity.
public static bool IsForeignAsset(EntityId entityId)

Parameters

entityId

The EntityId of the asset to check.

Returns

Type

Description

boolTrue if the asset is a foreign asset. Otherwise, false.

Remarks

A foreign asset is an asset that wasn't created in Unity, for example a .png texture file. During import, Unity creates a serialized representation of a foreign asset in the
Library
folder of the project. This happens when you first add the asset, when it changes outside Unity, and when you change its import settings. An asset that Unity creates, such as a material, is a native asset. For more information, refer to Native asset importers reference and AssetDatabase.IsNativeAsset.

IsForeignAsset(int)

Checks whether the asset with the specified instance ID is a foreign asset, created outside Unity.
Warning
Removed. Please use IsForeignAsset(EntityId) with the EntityId type instead.
public static bool IsForeignAsset(int instanceID)

Parameters

instanceID

The instance ID of the asset to check.

Returns

Type

Description

boolTrue if the asset is a foreign asset. Otherwise, false.

Remarks

This overload is obsolete. Use the overload that takes an EntityId instead.