Multiple Content managers?

I’ve been trying to use multiple Content mangers to manage images for different regions of a game. I know it’s best if I load all content at the beginning, but the game has (or will have) hundreds of sprites and other content that don’t need to exist in the background. I know using a content manager for each region is the best way to deal with loading and unloading content, but That’s where my problem is. I have no Idea how to manage more than 1 Content manager in a game.

Please help.

P.S. I know how to unload content and how to use the content manager. I also know how to define and draw sprites from Content.mgcb. The problem is using another content manager such as Test.mgcb. That, I have no Idea How to do.

The mgcb files are for the MonoGame pipeline tool, is this what you are refering to?

yes. From what I understand, the content managers should each correspond to a different .mgcb file. That would then make the unloadcontent function correspond to different .mgcb files, and thus diffrent content mangers. Am I wrong?

Oh I see… No the mgcb doesnt load or unload anything in your application. You use it to convert music and graphical files into a .xnb format. you stick them with your application and call the content.Load("FileName) from inside your game class.

The only reason you may want to have multiple mgcb files is to have different configurations for how your files compile to the xnb, like being optimized for one OS or another, or being compressed or not and stuff like that.

Then How would you split up your content? I’m getting stuck on how to load only the parts of the content that I want. I read about the contentmanager Constructor, but have no idea how to use it.

You might want to start on this series…

I already saw it, so I skimmed through some videos that I might have missed. It didn’t actually have the answer, but I think I figured it out. I used an if statement in loadcontent function, that way I could control what data gets loaded. So every time I unload all the data, I only load what I need for each scene. It seems to work so far, but if there are any more efficient ways, I’d love to hear them.

That isn’t necessary. You can easily just have a single content project and many ContentManager instances within your game. Usually i split things into at least a few content managers:

  • Common content… stuff that you use thru out the game and never need to unload.
  • UI content… content for the game menus that you want to unload once you are in game.
  • Level content… usually you have one or more of these depending on how your level transitions work.

The trick is just to always use the right content manager when you are loading something and not load the same content from more than one manager (it will just waste memory with duplicate loaded content).

3 Likes

lol sorry i couldnt figure out how to better help him tom xD

Just thought I would add my two cents to it.

So how do you create another instance of ContentManager ?

I’m new to MonoGame so i’m probably doing something wrong, but I can’t seem to find anything that works, so any help would be greatly appreciated.

@Samuel_Hopkins

using Microsoft.Xna.Framework.Content;

        public ContentManager UIElements;

I have no idea if the class instance should be public or private [It should] but for future, hold CTRL and click on say Content in Content.RootDirectory and you can take a closer look that way.

I used that method to work out what was missing and allowed VS to add the missing Using for me.

Hope this helps.

Thank You @MrValentine

1 Like