Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question [SerializeField] not working in my extended class

Discussion in 'UGUI & TextMesh Pro' started by Teraflare, Nov 8, 2023.

  1. Teraflare

    Teraflare

    Joined:
    Mar 17, 2019
    Posts:
    3
    Hello Everyone!

    I have problem with [SerializeField] in my class.
    I extended the unity Scrollbar class and wanted to add some extra attributes to use, but they are not showing on the inspector in normal mode (in debug mode they are shown in white).
    Currently I'm in workplace and have no code (I will add the real one when I'm home) but it is like this:

    /*necessary imports*/
    public class EnhancedScrollbar : Srcollbar {

    [SerializeField]
    private string Something;

    public string something{get {return Something;} set {Something = value;}}
    }

    Can somebody help me what do I have to do to see the "something" it in the inspector view after the onchange event of the scrollbar?
    I saw that the Scrollbar has the [ExecuteAlways] which is for the script to be executed not only on run but even on the editor. Does it have anything to do with my problem?
    I know that the main problem when we can't see the [SerializeField] in the inspector is that usually there is a compilation problem, but I don't see any error anywhere.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,082
    Assuming you're talking about Scrollbar, it's presumably because it has its own Editor named ScrollbarEditor.

    You'll need to copy that, rename it, associate it with your own type adding in your own field.

    If you show the inspector in Debug mode it'll not use the custom editors so you'll see the "raw" serialized fields of which the one you added will be there.
     
  3. Teraflare

    Teraflare

    Joined:
    Mar 17, 2019
    Posts:
    3
    Thank you very much! That is the scrollbar I was talking about. I will try it out when I went home after work! Thanks for the quick answer!
     
  4. Teraflare

    Teraflare

    Joined:
    Mar 17, 2019
    Posts:
    3
    Tried it and it worked! Thank you so much!
     
    MelvMay likes this.