# CanOpenAssetInEditor

> Checks whether the Unity Editor can open the asset with the specified EntityId.

## Definition

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

## CanOpenAssetInEditor(EntityId)

Checks whether the Unity Editor can open the asset with the specified EntityId.

```csharp
public static bool CanOpenAssetInEditor(EntityId entityId)
```

### Parameters

**** (\[EntityId]\(/engine/7000.0/script-reference/unityengine/entityid)): The EntityId of the asset to check.

### Returns

| Type                                                          | Description                                                                                                                                     |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if [AssetDatabase.OpenAsset](/engine/7000.0/script-reference/unityeditor/assetdatabase/openasset.md) can open the asset. Otherwise, false. |

### Remarks

Use this method to check whether calling [AssetDatabase.OpenAsset](/engine/7000.0/script-reference/unityeditor/assetdatabase/openasset.md) would open the asset. The asset must be saved to disk. Otherwise, the method always returns false.

### Examples

```csharp
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

[CreateAssetMenu(fileName = "MyObject", menuName = "ScriptableObjects/MyObject", order = 1)]
public class MyObject : ScriptableObject
{
    public string myData;

    [OnOpenAsset]
    public static bool Open(EntityId entityId)
    {
        if (AssetDatabase.GetMainAssetTypeAtPath(AssetDatabase.GetAssetPath(entityId)) == typeof(MyObject))
        {
            Debug.Log("Opening asset");
            return true;
        }
        else  return false; // This method doesn't handle opening of different asset types
    }

    [OnOpenAsset(OnOpenAssetAttributeMode.Validate)]
    public static bool WillOpen(EntityId entityId)
    {
        if (AssetDatabase.GetMainAssetTypeAtPath(AssetDatabase.GetAssetPath(entityId)) == typeof(MyObject))
        {
            // We can open MyObject asset using MyObject opening method
            Debug.Log("This asset can be opened by OnOpenAsset marked method");
            return true;
        }
        else  return false; // The passed instance doesn't belong to MyObject type asset so we won't be able to open it using opening method inside MyObject
    }

    [MenuItem("Test/WillOpenInUnity")]
    public static void WillSelectionBeOpenedInUnity()
    {
        AssetDatabase.CanOpenAssetInEditor(Selection.activeObject.GetEntityId());
    }
}
```

## CanOpenAssetInEditor(int)

Checks whether the Unity Editor can open the asset with the specified instance ID.

> **Warning:**
>
> **Removed.** Please use CanOpenAssetInEditor(EntityId) with the EntityId parameter type instead.

```csharp
public static bool CanOpenAssetInEditor(int instanceID)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The instance ID of the asset to check.

### Returns

| Type                                                          | Description                                                                                                                                     |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if [AssetDatabase.OpenAsset](/engine/7000.0/script-reference/unityeditor/assetdatabase/openasset.md) can open the asset. Otherwise, false. |

### Remarks

This overload is obsolete. Use the overload that takes an [EntityId](/engine/7000.0/script-reference/unityengine/entityid.md) instead.
