- Home /
Question by
MDJ9999 · Sep 12, 2020 at 11:25 AM ·
listscriptableobjectcopy
Copy of List with scriptableObjects?
I have a scriptableObject that have a List of other scritableobjects:
public class RoomSO : ScriptableObject
{
public List<ButtonSO> buttons;
public string roomname;
[TextArea(10,40)]
private string roomtext;
}
Then in my code when i remove a button from my list (buttons): currentRoom.buttons.RemoveAt(0);
Well, that changes my initial RoomSO instance also. If i restart Unity...everything is back to normal. But this is really annoying. So i thought of a solution of making a copy of the buttons like this:
List<ButtonSO> ls = new List<ButtonSO>();
foreach (var bt in currentRoom.buttons)
{
ls.Add(Instantiate(bt));
}
currentRoom.buttons = ls;
But i get a Type Mismatch error. I really don´t know how to solve this issue. Any help appriciated!
Comment