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. Dismiss Notice

Question Getting reference to a class that is not a monobehavior from inside a custom editor class

Discussion in 'Scripting' started by puddleglum, May 27, 2023.

  1. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    380
    im very very new to editor classes and have red some documentation, and watched some videos but they all talk about monobehaviors or scriptable objects. and not classes that dont inherited from anything. and i dont know the right wording to get any good google results, heres my code

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. using UnityEngine;
    6. #if UNITY_EDITOR
    7. using UnityEditor;
    8. #endif
    9. public class Attacks
    10. {
    11.  
    12.  
    13. #if UNITY_EDITOR
    14. [CustomEditor(typeof(Attacks))]
    15.     public class AttackCustomEditor : Editor
    16.     {
    17.         public override void OnInspectorGUI()
    18.         {
    19.         base.OnInspectorGUI();
    20.         Attacks AttacksCast = (Attacks)target;
    21. }
    22.  
    23.  
    24.  
    25. }
    26. #endif
    27.  
    the error im getting thrown is
    "cannot convert type 'unityEngine.Object' to 'Attacks' "

    ik this is a pretty easy one to solve and find on my own but iv been trying for like 20 minutes now and i cant find the right words to get the right results, ps the code works fine if i do public class attacks : monobehavior
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,883
    You need to use a PropertyDrawer for non-Unity objects.
     
    Bunny83 likes this.
  3. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    380
    ah so this is one of those things where im just so inexperienced that i have 0 clue what im looking at lol, ill spend the next couple days studying this syntax and looking up yt videos, thx for pointing me in the right direction
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,883
    The Unity docs explain their usage pretty clearly. I would just start there.
     
    Bunny83 and puddleglum like this.