Editor is of type Object

For some reason my editors keeps throwing errors when I try and cast the target as the custom editor type. When I add the [CustomEditor(typeof(MyScript))] i expect target to be of type MyScript but when I debug it is of type Object. This throws literally hundreds of errors on every domain reload (which is the only time the problem occurs). The errors are also thrown when no objects are being inspected which I believe might be part of the problem. I am using 2020.2.1.

This is precisely as specified in the docs.

https://docs.unity3d.com/ScriptReference/Editor-target.html

It’s up to you to cast it to MyScript.

Should have mentioned that I do indeed cast the target. That is where the error comes from as it can not cast a target of type Object to type MyScript.

Does your script inherit from UnityEngine.Object ? If it doesn’t, this cast will fail.

It inherits from ScriptableObject. The problem only occurs on domain reload when no inspectors are selected so I don’t think it is directly connected to the editor type but rather that the editor is initialised when it is not inspecting anything. This happens for all of the editors that have ScriptableObject targets.

This might be a stretch, but did you perhaps change the structure of your inheritance?

Here’s a simple use case that can muck things up:

  • inherit ScriptableObject to make Potion

  • make lots of potions

  • later decide to generalize it and make ScriptableObject → Item → Potion (for example)

Now all the objects you made that are Potions will need to be deleted and recreated.

Yes, I have indeed changed the structure. Although I do believe that all of the objects have been replaced since then. The error has also randomly disappeared as in “I did not get it a single time today”. Might come back later through, but thanks for the help.

1 Like