reload level whilst saving certain objects, without dontdestroy()

Hey guys, need a second opinion. i have a 2d level based physics game where the player can move round certain objects, now if the player wins, they proceed to the next level, but if they lose, the game reloads, but i want the dragged objects to remain in their positions after the reload of the current level. I can’t really use dontdestroyonload, i don’t think anyway, because i have so many static variables in the inspector that would need reassigning if i preloaded the objects in an empty scene beforehand, but if i load them in the game scene obviously on reload duplicates are formed. any ideas?

Edit: sort of like carrying over the specified objects into the next scene, and replacing the originals from the reload with them…

I don’t see a way around it, but it’s hard to suggest things without knowing more detail. But, one method I can suggest that might have minimal impact:

  • Upon level load, look for a GameObject called “GameBoard” which contains a script that holds an array of all of the board item positions plus a reference to the current level name/number.
  1. If it does not exist, then create the board as usual. Create a new GameBoard object and set its level number/name appropriately. Set DontDestroyOnLoad() on GameBoard so that it does not get deleted when reloading.
  2. If it exists, but the level number/name does not match, then destroy it and then do #1.
  3. If it exists and the level number/name matches the current level number/name, then just read the positions and move the board pieces appropriately.
  4. As the board pieces are moved, updated the GameBoard script.

i ended up putting the objects i needed to keep and not destroy in a preload screen, and covering that with a load texture, then with don’t destroy on load the reset doesn’t create duplicates, as i destroy the objects and reset them.