- Home /
How to preserve array of custom objects in inspector?
I have an array of custom objects (ScriptableObjects called "SlotData") in my main controller script like so:
public class RosetteController : MonoBehaviour
{
public SlotData[] slots = new SlotData[15];
void Awake()
{
for ( int i = 0; i < slots.Length; i++ )
{
slots[i] = (SlotData) ScriptableObject.CreateInstance("SlotData");
}
}
}
I've made a custom editor script that lets me see & edit all of the custom object variables in the inspector (I had to do this as I'm using setters & getters in the custom "SlotData" class)
However, the objects in the array only seem to exist during runtime - once I come out of playmode, all of the objects in the array are destroyed which is causing me some problems.
The inspector knows & shows that 15 SlotData objects are in the array, but the actual objects that the arry elements refer to are set back to null on exiting playmode - if I try to look at any of the elements of the array outside of playmode, there's nothing there.
Is there any way to get Unity (or the inspector) to preserve the objects or values that are created/assigned to the array outside of playmode?
For example, if my array were an array of ints, the elements of the array would be preserved outside of playmode - I could see & edit the elements in the array (int values) in the inspector.
I'd like to be able to do the same with my custom objects, but I can't figure out how to get Unity to preserve my objects.
Your answer
Follow this Question
Related Questions
Unable to see custom object in Inspector. 0 Answers
Array of abstract class in inspector 2 Answers
Adding an object to an array of custom objects (JS) 1 Answer
Add custom properties to Objects 1 Answer
Inspector button for custom class 1 Answer