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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Can't change values of List element inside inspector

Discussion in 'Scripting' started by Nefelyth, Sep 10, 2023.

  1. Nefelyth


    Jan 29, 2021
    I'm not sure if it's a bug or some kind of a setting which i don't know of, but I'm unable to change values in inspector inside a List of a nested class in ScriptableObject after I run a game. If i force to recompile my scripts or add and delete element of this list - it solves this problem until i run a game again which is not very destructive, but quite annoying to do this all the time if i just need to see how my game works with different values.
    Code (CSharp):
    1. public class MiniGameLevels : ScriptableObject
    2. {
    3.     public virtual float complexityFactor { get; set; }
    4. }
    Code (CSharp):
    1. public class MGRBT_Levels : MiniGameLevels
    2. {
    3.     [SerializeField] List<GameModes> gameModes;
    4.     [HideInInspector] public GameModes GameMode;
    6.     public void UpdateComplexity()
    7.     {
    8.         if (complexityFactor < 1) GameMode = gameModes[0];
    9.     }
    12.     [Serializable]
    13.     public class GameModes
    14.     {
    15.         public string Name;
    16.         public bool IsSequenceZoneActive;
    17.         public MGRBT_GridParameters GridParameters;
    18.         public bool UseActiveGridZone;
    19.         public Vector2Int ActiveGridZone_Min;
    20.         public Vector2Int ActiveGridZone_Max;
    21.         public List<ButtonAvailability> ButtonsAvailable;
    22.     }
    23.     [Serializable]
    24.     public struct ButtonAvailability
    25.     {
    26.         public MGRBT_Button Button;
    27.         // 0 - for infinite
    28.         public int Amount;
    29.     }
    30. }
    Last edited: Sep 10, 2023
  2. Bunny83


    Oct 18, 2010
    There are countless of things unclear. First of all you showed us 3 types, two are marked as serializable (GameModes, ButtonAvailability) one is not (MGRBT_Levels). That may be a scriptable object but we don't know that since we don't know what "MiniGameLevels" is. We also don't know what "MGRBT_Button" and "MGRBT_GridParameters" are.

    We still don't know what "values" you actually changed that did not persist. We also don't know if any of your types have custom property drawers or custom inspectors which may be implemented wrongly.

    Apart from that note that you serialized the "gameModes" as well as "GameMode" field. Keep in mind they are serialized separately. That means when you assign the first element of your gameModes array / list to the GameMode field, both will contain the same instance reference. However after serialization / deserialization the GameMode field will have it's own duplicate instance that has no connection to the element stored in the List.

    So it's really difficult to actually understand your problem here or what exactly went wrong.
  3. Nefelyth


    Jan 29, 2021
    Sorry, for not describe it properly, i updated my code there.. but my problem is that in inspector, after running my game i can't press or change any field values here: image2.png

    But basically speaking this script contains starting conditions of my minigame and depending on complexity it chooses which gamemode to use (for now it's only one). I can insert other script codes also, if you think it's needed, but i think it will lead away from my problem. Don't know

    Attached Files:

    Last edited: Sep 10, 2023
  4. Nefelyth


    Jan 29, 2021
    But actually, thanks really!
    I changed
    Code (CSharp):
    1.  [HideInInspector] public GameModes GameMode;
    Code (CSharp):
    1. [NonSerialized] public GameModes GameMode;
    and it solves it.