0
\$\begingroup\$

I'm trying to use an ObservableCollection in a ScriptableObject, but it doesn't generate any serialized field in the asset editor.

Here is my code:

[CreateAssetMenu(fileName = "Dictionnary.Asset", menuName = "dictionnary")]
public class TADictionnary : ScriptableObject
{
    [SerializeField]
    public ObservableCollection<TAVerb> verbs;
}
[Serializable]
[CreateAssetMenu(fileName = "Verb.Asset", menuName = "verb")]
public class TAVerb : ScriptableObject
{
    public List<string> synonyms;
    public string keyword;
}

I've read it used to not work on older unity version, but I'm using LTS 2022.3. So I'm not sure why it doesn't work.

\$\endgroup\$
3
  • \$\begingroup\$ Did you read anything saying this should work in version 2022? I don't recall seeing serialization of ObservableCollections in any of the update notes in Unity's version log. This related Q&A on StackOverflow shows how to implement your own version that serializes correctly for Inspector display. If you're using another source for your ObservableCollection, be sure to specify/link it in your question. \$\endgroup\$ Commented Oct 30, 2023 at 11:23
  • \$\begingroup\$ And is there a specific reason you need to use a ObservableCollection and not any of the other Collections available? \$\endgroup\$ Commented Oct 30, 2023 at 11:36
  • \$\begingroup\$ @DMGregory, I've seen that post, but I prefer to use native classes instead of implementing custom ones. But if I don't have any other options, I will implement that solution. \$\endgroup\$ Commented Oct 30, 2023 at 14:16

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.