Hello, Can anyone help me with scriptable objects?
So, I’m trying to make an editor script for the scriptable object so that it shows toggle buttons and I can store where obstacles need to be instantiated on the grid. But, currently what happens is when I hit play or restart unity or recompile scripts the scriptable object gets reset.
Below are the relevant scripts:
Obstacle Editor:
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(ObstacleData))]
public class ObstacleEditor : Editor
{
public override void OnInspectorGUI()
{
ObstacleData obstacleData = (ObstacleData)target;
for (int row = 0; row < 10; row++)
{
EditorGUILayout.BeginHorizontal();
for (int col = 0; col < 10; col++)
{
obstacleData.blockedTiles[row,col] = EditorGUILayout.Toggle(obstacleData.blockedTiles[row,col]);
}
EditorGUILayout.EndHorizontal();
}
if(GUI.changed)
{
EditorUtility.SetDirty(obstacleData);
}
}
}
ObstacleData:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "ObstacleData", menuName = "ScriptableObjects/Obstacle Data")]
public class ObstacleData : ScriptableObject
{
[SerializeField] public bool[,] blockedTiles = new bool[10,10];
}