sinbad / SPUD

Steve's Persistent Unreal Data library
MIT License
300 stars 44 forks source link

Restore Level, Array has changed during ranged-for iteration! #48

Closed shoooxz closed 1 year ago

shoooxz commented 1 year ago

Hello I had sometimes problem with RestoreLevel function and particulary with: // Restore existing actor state for (auto Actor : Level->Actors) 458 line SpudState.cpp keep getting [2023.02.06-09.57.53:422][450]LogOutputDevice: Error: Array has changed during ranged-for iteration! crash I managed to fixed it with coping an array: TArray<AActor*> LevelActors = Level->Actors; // Restore existing actor state for (auto Actor : LevelActors) Wondering, Is this even a good aproach. Error occurs when I spawn runtime actors, In my case pawns with new interface GetSpudRespawnMode AlwaysRespawn.

Regards

sinbad commented 1 year ago

SPUD doesn't spawn any actors during that loop, it always spawns them just before precisely to avoid that sort of problem. So I guess it must be that you're spawning actors yourself during one of the pre/post restore hooks?

Copying the array beforehand would fix it but there can be a lot of actors in a level so it's best not to. Instead of spawning your own actors you could mark those as SPUD objects and SPUD will restore the links between them on restore.