Reputation: 13
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]);
}
}
}
Upvotes: 0
Views: 6605
Reputation: 276
You can't modify the collection while looping through it.
In your case you can just use this:
completedObjectives.Remove(questToRemove);
Upvotes: 1