This project has moved and is read-only. For the latest updates, please go here.

How to remove content from contentmanager(XNA 4.0)

Topics: Developer Forum, Project Management Forum, User Forum
Oct 27, 2010 at 3:03 AM

Hi, everybody.

I have a problem during developimg a simple game, so I visit here.

of course, my problem is no matter with farseer engine.

It is only regarding to XNA 4.0.

But the reason that I visit to fix it here is that I have always fixed my problems in developing my game.

Then from now on, I will explain about my problem.

My game has many levels.

But every levels has its own contents(images and fonts and sounds . . .).

I need to remove the contents in the level everytime one level finish.

ContentManager has the method called "Unload".

however, the method removes all contents in the whole game.

How can I do?

Oct 27, 2010 at 10:19 AM

As you no doubt are aware, this question is much more likely to be answered over at the new AppHub:

There are two ways you can achieve this:

1) Simple way: Create a new ContentManager for every level you load and Unload it when you go to a new level or back to the menu system. Disadvantage is that you can't share assets between different content managers

2) More difficult (not recommended) way: Subclass ContentManager, override the Load<> and add a Remove method.

Oct 28, 2010 at 2:09 AM

Thank you .

But I don't understand well yet.

Regarding to first way, when creating a new ContentManager, how can I connect it to the main game?

Sorry for my lacking tech . ..

Oct 28, 2010 at 4:01 AM

I really shouldn't answer this question but....

You need to create a system that allows your game to load and unload individual assets. I recommend using a Dictionary<string, T> to store all your content and allow easy loading and unloading with names. I won't get into details as this is definitely an AppHub question.

Best of luck.

Oct 28, 2010 at 4:03 AM
I asked it to you because I can't see the link you gave me.
Oct 28, 2010 at 8:34 AM

Hi blackdragon1027, I think that the best place to ask this question, and where you have more chances to receive a better answer is here: