Is there a way for a public/serializedfield to be uneditable and just grayed out in the inspector?

Is there a way for a public/serializedfield to be uneditable and just grayed out in the inspector.

Something like this:
68612-capture.png

Like this:

    [HideInInspector]
    public int SomeInteger = 5;
    [HideInInspector]
    public GameObject SomeGameObject;

It might not be grayed out, but it can’t be edited from the inspector. Hope that helps!

I have an idea, is more of a workaroud than a real solution, you could do this:


using UnityEngine;

[ExecuteInEditMode]
public class YourFileName : MonoBehaviour {
        private string variableA = "hi";
        public string publicVariableA;

        private int variableB = 1;
        public int publicVariableB;

        #if UNITY_EDITOR
        //This code wont execute on the game build
        private void Update(){
             if (!Application.isPlaying()) {
                  //This code will run only in edit mode
                  publicVariableA = variableA;
                  publicVariableB = variableB;
             }
        }
        #endif
}

I wrote this on my phone so there could be some sintax errors, have a great day!