[ShowInInspector]don't store data

Issue #888 resolved
Meru Meru created an issue

I use code below to store and to adjust something’s positiong in grid.

        [ShowInInspector] public Vector2Int pos {
            get => _pos;
            set => _pos = value;
        }
        private _pos;

Then I change the value of it on the inspector to (1, 0), but when I hit the play button, the value change back into (0, 0). I found it that the value even wasn’t (1, 0) when unity execute Awake() in debugging mode.

Comments (5)

  1. Salomon Zwecker

    This is the desired behavior. ShowInInspector is usually used for debug purpose to be able to see certain values while in play mode. It does not serialize anything.

    What you probably want to do instead is this:

            [UnityEngine.SerializeField] Vector2Int _pos;
    

  2. Log in to comment