x


Delete Objects Belonging To A Specific Scene

Let's suppose that I used an Application.LoadLevelAdditive() instruction to load a "Menu Scene" over my main game scene, just to allow the user to do in game adjustments to his preferences.

When a "Resume Game" is clicked the menu scene should be removed and the game should go on.

While the problem keeps that simple I can just manually remove the component created to render the menu, but let's suppose that for some reason I had to load a huge scene over another, and now I need to clear ONLY the objects belonging to a specific scene.

How do I do that?

I tried answering myselft with some possibilities:

1) Saving scene data somewhere and then reload it (deleting everything) and restoring data?

2) Flagging somehow (how?) all specific scene objects so I can delete them all?

3) Calling a magic method deleteLevel() which I don't know if exists? ^^

Is any of those a best solution?

Is there something else I should know?

Thanks in advance for the answers!

more ▼

asked Apr 12 '11 at 08:46 AM

FrHaYwOrKs gravatar image

FrHaYwOrKs
271 4 6 19

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

1 answer: sort voted first

Hi,

Interesting questions! willing to know now :). I never formulate that question consciously and just assumed I had to roll my own system.

To answer question 2: What I do is put a specific component that manage such meta data and query that instead of relying on some built in feature. This allow me for more flexibility obviously and it can change at runtime as well (say an object becomes part of the current contact and must not be destroy now).

The system I have in place has a main application with the navigation system and other fancyness that ARE always present throughout the game. All its content is set to not be destroyed on level load. Then, when I need to load a new level, I simply load that main application again, and then load the level in question, which effectively removes all GO that should be destroyed on level load. It might not fit your purpose as is, but could be a starting point. You can do this with loading an empty level as well ( never tried).

Hope that make sense.

Jean

more ▼

answered Apr 12 '11 at 09:17 AM

Jean Fabre gravatar image

Jean Fabre
3.1k 68 75 103

Thanks a lot! So you say that option 2 is working fine with you, and I think it may be the best solution, after all! When you talk about "adding a component that manages such meta data" you mean just a script with a custom variable? In that case, what should happen if, checking for objects, I should try to access that script on something that doesn't have it? Thanks again Jean! :)

Apr 12 '11 at 09:27 AM FrHaYwOrKs

Hi, yes, a script with a public variable for example ( but you can go beyond that because your system will likely have to change over time ( use an enum for example to have a predefined set of states easily maintainable). If the object or component doesn't exists, you will get a null when trying to get that component from a given gameObject, then you know it doesn't have that metadata and can act accordingly.

Apr 12 '11 at 10:49 AM Jean Fabre

That's perfect! You've been really kind Jean, thanks a lot for your help! :)

Apr 12 '11 at 11:30 AM FrHaYwOrKs
(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:

x1095
x718
x116

asked: Apr 12 '11 at 08:46 AM

Seen: 1559 times

Last Updated: Apr 12 '11 at 08:46 AM