Hi,
I’m trying to create custom asset with its own editor window.
I have the following code for creating my asset:
[CreateAssetMenu(fileName = "My new asset.myasset", menuName = "Create My New Asset")]
[System.Serializable]
public class MyAsset : ScriptableObject {
[SerializeField, Multiline]
public string description;
}
And the following for opening editor window:
[UnityEditor.Callbacks.OnOpenAsset(1)]
public static bool OnOpenAsset(int instanceID, int line)
{
if (Selection.activeObject as MyAsset != null)
{
ShowEditor();
return true;
}
return false;
}
The problem is Selection.activeObject returns null when converted to MyAsset.
Debugging shows that when I select my asset, it is of type DefaultAsset, but other assets like Animation Controller or a Game Scene have the correct types.