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

Can't view custom classes in editor, thanks unity.

Discussion in 'Editor & General Support' started by MosquitoByte, Aug 30, 2020.

  1. MosquitoByte

    MosquitoByte

    Joined:
    Sep 17, 2018
    Posts:
    213
    While working with custom classes in unity i realized their data often cannot be read by the inspector, so i looked for a workaround and found this:


    however it does not work. Code below
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System;
    5.  
    6. [CreateAssetMenu]
    7. [Serializable]
    8. public class Unit : ScriptableObject
    9. {
    10.     public string UnitName;
    11.  
    12.     #region stats
    13.    [SerializeField] int base_hp;
    14.    [SerializeField] int base_mp;
    15.    [SerializeField] int base_atk;
    16.    [SerializeField] int base_def;
    17.    [SerializeField] int base_speed;
    18.  
    19.     public int current_hp;
    20.     public int current_mp;
    21.     public int current_atk;
    22.     public int current_def;
    23.     public int current_speed;
    24.     #endregion
    25.  
    26.     private void Awake()
    27.     {
    28.         current_hp = base_hp;
    29.         current_mp = base_mp;
    30.         current_atk = base_atk;
    31.         current_def = base_def;
    32.         current_speed = base_speed;
    33.     }
    34. }
    https://i.gyazo.com/151abfabcbfc663c831bbc70651fbae9.png
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    The inline field editing doesn't work for objects which extend from UnityEngine.Object. you have to go to the source (the actual scriptableobject) to edit it, or use a custom editor.

    Alternatively, make your class not extend from Scriptableobject.
     
  3. MosquitoByte

    MosquitoByte

    Joined:
    Sep 17, 2018
    Posts:
    213
    *sigh*, fine, i'll make a custom editor. Where do i start.