- Home /
Why aren't lists editable in ScriptableObjects?
I'm trying to make a ScriptableObject I can use to define NPC movements in the editor by creating an instance of the SO for each NPC, populating it in-editor, then leaving it in the resources folder to be loaded at runtime when required. The implementation is pretty trivial:
[System.Serializable]
public class CharacterScheduleEntry
{
public string sceneName;
public int progressionFlag;
public string spawnPoint;
public string dialogueKey;
}
[CreateAssetMenu(menuName = "Character Schedule")]
public class BaseCharacterSchedule : ScriptableObject {
public string characterKey;
public List<CharacterScheduleEntry> scheduleList = new List<CharacterScheduleEntry>();
}
This looks fine, but when I actually create an asset of type BaseCharacterSchedule, scheduleList is visible but always has 0 indices; if I attempt to manually change its size to anything, it immediately reverts back to 0. I've tried playing/stopping and restarting the editor, and even changing scheduleList's type from my own custom class to , but nothing seems to work- is it simply not possible to use lists in a SO?
Do you have a custom editor for BaseCharacterSchedule? Is this the entirety of the code for BaseCharacterSchedule?
That is indeed the entirety of the code for it- is a custom editor required? I assumed that since the component variables were all simple types, I could get away with just editing the list directly.
No it is not required, but the symptom you described is common in custom editors that have been implemented incorrectly.
I tried using your example code verbatim and cannot reproduce the problem. Everything seems to work for me as expected.
I'm assu$$anonymous$$g this is the only place you're seeing this problem? $$anonymous$$g., you don't have an event handler for Undo.postprocess$$anonymous$$odifications somewhere?
This is definitely the only place I'm using it, since I made both classes brand-new to work out how to use scriptableobject... are you on 2017.1.0p4? Because I just created a brand-new project as well, but cutting & pasting the code I posted above results in the same weirdness.
I did find a reproducible way to eli$$anonymous$$ate the problem, but it's weird as heck- if I include multiple, identical lists, like the following, every list but the bottommost is editable:
public List<CharacterScheduleEntry> characterSchedule1;
public List<CharacterScheduleEntry> characterSchedule;
public List<CharacterScheduleEntry> characterSchedule0;
Apparently it's not limited to lists, as creating a filler int under the list, editing the asset in the inspector, then deleting said int leaves the list editable. I must be doing something weird here by mistake, but it bugs me that I can repro it in a clean project.
Does this happen for you in an official (i.e. non-patch) release?
Your answer
Follow this Question
Related Questions
Add lines to a script from another script 0 Answers
Serialization issue with ScriptableObject 0 Answers
How to work with custom class (ScriptableObject) SerializedProperty? 1 Answer
Why is play mode reverting my scriptableobject to a previous serialized state? 2 Answers
[Solved]How to serialize Dictionary with Unity Serialization System 6 Answers