So I’ve just spent several hours wondering why one of my database assets won’t save. After reading as many resources as I could find on the subject, none of the solutions worked. These included SetDirty and almost every other method belonging to the AssetDatabase class.
However, my problem was that manually implemented properties are apparently what I’m meant to be using:
using System;
[Serializable]
public class Item
{
[SerializeField] private int _id;
//Constructors etc
public int Id
{
get { return _id; }
set { _id = value; }
}
}
Whereas auto-implemented properties, which are far less prone to manual entry errors and are simply less taxing to read and write do not:
using System;
[Serializable]
public class Item
{
//Constructors etc
[SerializeField] public int Id { get; set;}
}
Is this a C# language problem that I’m not aware of? Or is this something that Unity does specifically? I’m slightly put off by the idea of using .asset files now if it means typing out 400% more boiler plate.