This repository was archived by the owner on Jul 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
This repository was archived by the owner on Jul 11, 2025. It is now read-only.
Check if gameobjects going to be removed in OnShutdown-Method #381
Copy link
Copy link
Open
Labels
CoreArea: Duality runtime or launcherArea: Duality runtime or launcherHelp WantedContributions especially appreciatedContributions especially appreciatedNice2HaveBeneficial, but only very slightly soBeneficial, but only very slightly soTaskToDo that's neither a Bug, nor a FeatureToDo that's neither a Bug, nor a FeatureUnit TestsGood candidate for adding more testsGood candidate for adding more tests
Milestone
Description
Summary
The engine throws an exception when you remove gameobjects in the OnShutdown-Method.
How to reproduce [Bugs]
Here is my code:
private List<GameObject> enemies = new List<GameObject>();
public void OnInit(InitContext context)
{
if (context == InitContext.Activate)
{
// add some gameobjects and put them into the list.
}
}
public void OnShutdown(ShutdownContext context)
{
if (context == ShutdownContext.Saving)
{
foreach (var enemy in enemies)
{
Scene.Current.RemoveObject(enemy);
}
}
}What's my plan?
I like to keep track of "enemies" and I want to remove them after exiting the sandbox-mode.
Attachments
The Exception:
[Core] Error: OnSaving() of Scene "Data\Scenes\TestLevel" failed: InvalidOperationException: Collection was modified; enumeration operation may not execute.
CallStack:
at System.Collections.Generic.HashSet`1.Enumerator.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at Duality.Resources.Scene.OnSaving(String saveAsPath) in c:\projects\duality\Duality\Resources\Scene.cs:line 942
at Duality.Resource.CheckedOnSaving(String saveAsPath) in c:\projects\duality\Duality\Resource.cs:line 215
Jeah, I know that I try to remove gameobjects when the engine wants to save them.
Metadata
Metadata
Assignees
Labels
CoreArea: Duality runtime or launcherArea: Duality runtime or launcherHelp WantedContributions especially appreciatedContributions especially appreciatedNice2HaveBeneficial, but only very slightly soBeneficial, but only very slightly soTaskToDo that's neither a Bug, nor a FeatureToDo that's neither a Bug, nor a FeatureUnit TestsGood candidate for adding more testsGood candidate for adding more tests