XNA How do I create a separate ContentManager?

With XNA 4.0, I've tried to create multiple content managers for different game screens something like this:

ContentManager myManager = new ContentManager(Content.ServiceProvider, Content.RootDirectory);

      

when Content is the original ContentManager that the system provides me.

However, this didn't work as I expected. If I call myManager.Unload (), everything loaded by the original ContentManager will be unloaded as well. It was as if they contained the same data.

How can I separate them and make the unloading of one manager not affect the other?

+3


source to share


1 answer


There is nothing wrong with the code you posted. Personally, I use Game.Services

- but Content.ServiceProvider

fine too - they both point to exactly the same object.

The error must be elsewhere in your code. Are you absolutely sure you are using the right content manager for every occasion?



Have you tried running your code through the debugger? And using the Make Object ID function? (In the context menu for variables or view variables that you click with the mouse.)

+3


source







All Articles