IsForeignAsset
Determines whether a given asset is an external asset, also known as a foreign asset.
Read time 3 minutesLast updated 7 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor
IsForeignAsset(Object)
Determines whether a given asset is an external asset, also known as a foreign asset.
public static bool IsForeignAsset(Object obj)
Parameters
The object of the asset.
Returns
Type | Description |
|---|---|
| bool | Returns true if the asset is a foreign asset, and false otherwise. |
Remarks
A foreign asset is any asset that isn't created within Unity, for example a .png texture file. An asset created in Unity is a Native asset importers reference, for example a material or a prefab.
Unity creates a serialized representation of foreign assets in the Project's Library folder during import. This happens when the asset is first added, when it's updated externally, or when you modify its import settings in the Editor.
Additional Resources: 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)
Determines whether a given asset is an external asset, also known as a foreign asset.
public static bool IsForeignAsset(EntityId entityId)
Parameters
The EntityID of the asset.
Returns
Type | Description |
|---|---|
| bool | Returns true if the asset is a foreign asset, and false otherwise. |
Remarks
A foreign asset is any asset that isn't created within Unity, for example a .png texture file. An asset created in Unity is a Native asset importers reference, for example a material or a prefab.
Unity creates a serialized representation of foreign assets in the Project's Library folder during import. This happens when the asset is first added, when it's updated externally, or when you modify its import settings in the Editor.
Additional Resources: 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(int)
Determines whether a given asset is an external asset, also known as a foreign asset.
public static bool IsForeignAsset(int instanceID)
Parameters
The InstanceID of the asset.
Returns
Type | Description |
|---|---|
| bool | Returns true if the asset is a foreign asset, and false otherwise. |
Remarks
A foreign asset is any asset that isn't created within Unity, for example a .png texture file. An asset created in Unity is a Native asset importers reference, for example a material or a prefab.
Unity creates a serialized representation of foreign assets in the Project's Library folder during import. This happens when the asset is first added, when it's updated externally, or when you modify its import settings in the Editor.
Additional Resources: 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); } }}