I created a ScriptableObject as a custom asset. I then created a custom inspector for the class extending Editor. I can change the pamater values listed in the inspector but I can’t get the parameters changes to be saved. When I run the application the parameters go back to 0. I think I am not unsderstanding something basic. And a new instance is being created with out me knowing where.
Here is what the extended editor, for the class used as the asset, looks like:
CustomEditor(typeof(PuzzleLevelData))]
public class PuzzleLevelDataEditor : Editor
{
private PuzzleLevelData m_levelData; //Make an easy shortcut to the data you are editing
private SerializedObject m_levelDataSO;
public void OnEnable()
{
m_levelData =(PuzzleLevelData)target
m_levelDataSO = new SerializedObject(target);
}
public override void OnInspectorGUI()
{
int columnsCount = EditorGUILayout.IntField(“Number Of Columns”, m_levelData.GetColumnsCount());
int rowsCount = EditorGUILayout.IntField(“Number Of Rows”, m_levelData.GetRowsCount());
if( columnsCount < 0 )
columnsCount = 0;
if( rowsCount < 0 )
rowsCount = 0;
m_levelDataSO.Update();
if( columnsCount > m_levelData.GetColumnsCount() )
{
m_levelData.AddColumns( columnsCount - m_levelData.GetColumnsCount() );
}
if( rowsCount > m_levelData.GetRowsCount() )
{
m_levelData.AddRows( rowsCount - m_levelData.GetRowsCount() );
}
m_levelDataSO.ApplyModifiedProperties();
//I have also tried:
//EditorUtility.SetDirty(target);
}
}
I have tried it with an without the SerializedObject. So accesing the target straight.
The PuzzleLevelData is an object in the Project NOT in the Scene/Hierchy. Is that what the problem is. I am having trouble understanding the relation with the ScriptableObject that is NOT in the scene and when how an instance of that object is created. I think. Can someone educate me on this please?