How to execute a function of serializable class from editor?

I want execute the function “SetDefault()” when the variable “setDefault” is true.
i mean, i want set default values in the fields if it is necessary.
How can i do that?

Thank you so much!!

//-------------------------------------------------
[Serializable]
public class Hiter
{
    [TagSelector]
    public string hiterTag;
    public Colliders2D colliderType;
    public enum Colliders2D { BoxCollider2D, CircleCollider2D, CapsuleCollider2D };

}
//-------------------------------------------------

[Serializable]
public class Hiters
{
    public bool setDefault;

    public Hiter[] hiter = new Hiter[] { };

    void SetDefault()
    {
        Hiter hiter1 = new Hiter();

        hiter1.hiterTag = Tags.enemy;
        hiter1.colliderType = Hiter.Colliders2D.BoxCollider2D;
        hiter.SetValue(hiter1, 0);

        Hiter hiter2 = new Hiter();

        hiter2.hiterTag = Tags.player;
        hiter2.colliderType = Hiter.Colliders2D.BoxCollider2D;
        hiter.SetValue(hiter2, 1);
    }

}
//-------------------------------------------------

This is not a post for the 2D forum, it’s a scripting issue which should be posted in the scripting forum.

You can use the Start method to initialize stuff. There are other choices too.

Ok, i’m sorry, it is posible move the thread? or i must delete it and repost it there?

The Start method doest’n works insie of a serializable class becouse it is not a derivated class from Monobehaviour class and i want to see the changes on the editor fields and remember it.

No, there’s no need to move it this time, I was only mentioning it for future posts.

I apologise, I didn’t notice it wasn’t a MonoBehaviour for some reason, my mistake.

So is there a reason why you cannot use the class constructor for initialization to default?

The constructor does not works either. The editor create the instance but i can’t see the changes in the form fields. Or maybe i am not using the right way to change the form fields values.

6928040--813053--form.png

Maybe this article goes over enough to cover what you need, I’m not sure. It all depends on how you’re serializing this stuff.

The field was created like this

//Draw the popup box with the current selected index
index = EditorGUI.Popup(position, label.text, index, tagList.ToArray());

I only want set the index from the serializable class. Is it possible?

i’m using this script

https://answers.unity.com/questions/1378822/list-of-tags-in-the-inspector.html

Do you mean how i am doing it? i’m just doing it like this…

public class CanyonDamage : MonoBehaviour
{
    public Hiters hiters;
}