- Home /
Understanding ScriptableObjects?
I am trying to get the hang of SO. But i am a bit confused.
So i have set up this code (RoomSO):
[CreateAssetMenu(fileName = "New Room", menuName = "Rooms/Room")]
public class RoomSO : ScriptableObject
{
public List<ButtonSO> buttons;
public void AddButton()
{
ButtonSO bt = buttons[0];
bt.buttonText = "Hi";
buttons.Add(bt);
}
}
My ButtonSO looks like this:
[CreateAssetMenu(fileName = "New Button", menuName = "Rooms/Button")]
public class ButtonSO : ScriptableObject
{
public string buttonText;
}
As you can see from the RoomSO.AddButton i just created a couple of buttons in the editor and dragged them into the list (buttons).
The above code works...a button copy of the first button is added to the list.
But if i change RoomSO.AddButton to this:
public void AddButton()
{
bt = (ButtonSO) ScriptableObject.CreateInstance<ButtonSO>() as ButtonSO;
bt.buttonText = "Hello";
buttons.Add(bt);
}
And i look in the RoomSO in the assets, a third button is added...but instead of the "bt" button...i get a "Type mismatch".
Why? Is the because the list "buttons" holds a reference to SO in the assets folder and i am trying to add an actual instance that is not saved on disk but only is in memory? Or is it some seralization issue?
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Auto removing entries form a scriptableobject list when asset is deleted. 0 Answers
Copy of List with scriptableObjects? 0 Answers
Variable will not change? 1 Answer
Scriptable object sub-classes list 1 Answer