Skip to main content
Became Hot Network Question
Typo
Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Structuring a Scriptable Object so that it has a List ofor an Array of 2 other Scriptable Objects

Source Link
kanamekun
  • 379
  • 6
  • 23

Structuring a Scriptable Object so that it has a List of an Array of 2 other Scriptable Objects

I created three Scriptable Objects for my Unity word game:

  1. FeemData - This is to hold information on letters
  2. NeemData - This is to hold information on pronunciation
  3. SuperNeemData - This is to hold #1 and #2 together in a single Scriptable Object.

Here's the C# code for the SuperNeemData SO:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "New SuperNeemData", menuName = "Super Neem Data", order = 51)]

public class SuperNeemData : ScriptableObject
{
    [SerializeField]
    public FeemData actualFeem;

    [SerializeField]
    public NeemData superNeem;

}

So far, so good. But then I created a LevelData, which is meant to hold an arbitrary number of SuperNeemDatas:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "New LevelData", menuName = "Level Data", order = 51)]

public class LevelData : ScriptableObject
{
    [SerializeField]
    public List<SuperNeemData> SuperNeemForThisLevel;

}

When I go to the Inspector allows me to view and change the SuperNeemDatas in there, like this:

enter image description here

This works OK, but it's not the best workflow. In order to create a SuperNeemData, first I have to go into a separate folder and generate a SuperNeemData Scriptable Object and then drag the FeemData into there... and then drag a NeemData into there... and then go back to LevelData and drag the SuperNeemData Scriptable Object into there.

The whole process takes a lot of extra time and clicks. I'm hoping to change things so that I can drag FeemData and NeemData Scriptable Objects directly into the LevelData Scriptable Object.

In short (I think), I would like the LevelData Scriptable Object to have a List of an Array (with two items: first one is a FeemData and second one is a NeemData). Then if I am understanding things correctly, I could drag a FeemData So and a NeemData SO directly into the LevelData SO... a much easier workflow.

Any advice on how to structure a Scriptable Object so that it has a List of an Array of 2 other Scriptable Objects? Thank you!