Say I have a ScriptableObject Item:
public class Item : ScriptableObject
{
public new string name;
public string description;
public Sprite sprite;
}
The only issue is that the fields can be modified:
Item item = new Item();
item.description = "Overwrite";
I want them to be readonly. I found this workaround using properties:
public class Item : ScriptableObject
{
[SerializeField] private new string name;
[SerializeField] private string description;
[SerializeField] private Sprite sprite;
public string Name => name;
public string Description => description;
public Sprite Sprite => sprite;
}
The only issue is that this effectively doubles the length of all of my ScriptableObjects and seems cumbersome. Is there another preferred way to make ScriptableObject fields readonly without the extra code and still serializing fields?