'How to remove Element from list in Unity (in Inspector, Children of Elements)
I have QuestList which contants scriptable objects. I want Delete Elements when the quest is complete.
In "Element 0" there is another element "Completed Objectives" in the first quest "Quest A" when you start up the game quest is set to 0/1 when you finish objective quest is setup to 1/1 (I need to delete Quests so they don't show up after they completed)
how do i delete Elements in runtime? how i can add them? I been googling around 2 hours to find answer for this...
I try out this but doesn't work.
public void RemoveQuest()
{
for(int i = 0; i < completedObjectives.Count; i++)
{
if(completedObjectives[i] == questToRemove)
{
completedObjectives.Remove(completedObjectives[i]);
}
}
}
Solution 1:[1]
You can't modify the collection while looping through it.
In your case you can just use this:
completedObjectives.Remove(questToRemove);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andriy Marshalek |



