- Home /
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..
Answer by ratboy · May 07, 2012 at 11:54 PM
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.
Answer by chainedlupine · May 04, 2012 at 07:40 PM
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.
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.
If it exists, but the level number/name does not match, then destroy it and then do #1.
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.
As the board pieces are moved, updated the GameBoard script.
thanks for your response, 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 - sorted :) thanks anyway $$anonymous$$!