- Home /
Question by
leonardoraele · Mar 30, 2014 at 03:56 AM ·
guieditortargeteditorgui
Why can't I cast Editor.target to my CustomEditor type?
I'm getting the error: "Cannot convert type UnityEngine.Object' to
Mask'" when trying to cast Editor.target to my CustomEditor type. Why?
using UnityEngine;
using UnityEditor;
using System.Collections;
[UnityEditor.CustomEditor(typeof(Mask))]
public class MaskEditor : UnityEditor.Editor {
public override void OnInspectorGUI()
{
Mask mask = (Mask) target;
// ... Draw something with EditorGUILayout static methods ...
}
}
Mask is a simple class which doesn't extends nothing and has a System.Serializable annotation.
Comment
Is $$anonymous$$ask
a UnityEngine.Object
? (Check what's $$anonymous$$ask
inheriting from)
Best Answer
Answer by frarees · Mar 30, 2014 at 11:11 AM
target
refers to an actual UnityEngine.Object
. If Mask
is not convertible to that, it won't work. Use SerializableObject instead to successfully iterate over a custom serializable class.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141523im_/https://answers.unity.com/themes/thub/images/avi.jpg)