x


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..

more ▼

asked May 04 '12 at 08:49 AM

ratboy gravatar image

ratboy
41 18 21 22

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered May 07 '12 at 11:54 PM

ratboy gravatar image

ratboy
41 18 21 22

(comments are locked)
10|3000 characters needed characters left

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.
more ▼

answered May 04 '12 at 07:40 PM

chainedlupine gravatar image

chainedlupine
122 2 2 3

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 David!

May 07 '12 at 11:54 PM ratboy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x322
x133
x104
x85
x82

asked: May 04 '12 at 08:49 AM

Seen: 608 times

Last Updated: May 07 '12 at 11:54 PM