Search Unity

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

Question How to save changes that made in inspector

Discussion in 'Scripting' started by kinglotrich, Sep 5, 2023.

  1. kinglotrich

    kinglotrich

    Joined:
    Jun 2, 2023
    Posts:
    29
    upload_2023-9-5_16-47-0.png

    [System.Serializable]
    public struct AttiributeList
    {
    public string Attiribute;
    public short Value;

    }
    public AttiributeList[] attiributeList;

    whenever ı make new enemy ı have to create new elements of list and and give them name because script resets, but ı want to set their value only the rest can stay same. how can ı save inspector saves ? or can I adjust members of list in scripts ? their name dont need to be even public just [SerializeField] will be nice if ı can adjust it in scripts.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,015
    These fields should be saved when you change them in the Inspector and save the scene or prefab. If they don't "save" we need to see more of the script. Perhaps you are not considering somewhere that AttiributeList is a value-type. For example, this will NOT update the value in the list:

    var att = attiributeList[0];
    att.Value = -100;


    If you do that, this needs to be followed by an assignment since the above only modified a copy of the struct:

    attiributeList[0] = att;

    It's the same as when modifiying transform.position for example. You always need to reassign the position because Vector3 is a value type.

    If you want to copy these fields of the component, use the three-vertical-dots menu in the upper right corner of the component (here named: "Attributes Sc").
     
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,576
  4. kinglotrich

    kinglotrich

    Joined:
    Jun 2, 2023
    Posts:
    29
    You are a hero I am really grateful, it is totally what I need also I learned new thing.
    It ıs not releated but I want to ask something, maybe you know. I had a post but did get answer.
    Whenever ı do someting about prefabs I get memory leak warming even for empty game objects without anyting.