Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Bug Editor is of type Object

Discussion in 'Editor & General Support' started by Nexer8, Jan 2, 2021.

  1. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    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.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    32,353
  3. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    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.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    32,353
    Does your script inherit from UnityEngine.Object ? If it doesn't, this cast will fail.
     
  5. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    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.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    32,353
    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.
     
  7. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    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.
     
    Kurt-Dekker likes this.