Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The ContentManager in XNA 4.0 only has one Unload() method that Unloads all Assets.

I want to have some "global" Assets that are always loaded, but then I want per-Level Assets which should be Unloaded when the level is changed.

Should I create a second Instance of the ContentManager as part of the Level.cs Class? Or should I use Game.Content and then call .Dispose on the Assets I load? Or should I create my own ContentManager on top of the ReadAsset function as outlined here?

share|improve this question
add comment

1 Answer 1

up vote 12 down vote accepted

Create a second instance of ContentManager.

You should never Dispose() of things you load from a ContentManager (using the default implementation), as these instances are shared and reused.

Creating your own version of ContentManager is kind of orthogonal. Either way you'll be creating a second instance of ContentManager (or a class derived from it). So if the existing implementation suits your purposes - then use it, otherwise override what you want to change.

Of course, if your game is relatively small - then it won't really matter if you just use the one ContentManager and not bother unloading content between levels.

share|improve this answer
5  
+1 and a reminder to myself to link here next time someone tries to tell me how great the singleton pattern is for asset managers. –  user744 Nov 16 '10 at 9:41
    
I also found the Game State Management Demo at the XNA Web Site which uses exactly this (1 global Content Manager and a 2nd one on Screens that need it). Not very intuitive, but it'll do :) –  Michael Stum Nov 16 '10 at 16:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.