IcySnow
IcySnow

Reputation: 871

XNA How to create separate ContentManager?

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

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

with Content being the original ContentManager the system provides me with.

However, it didn't work out like I had expected. If I call myManager.Unload() then everything loaded with the original ContentManager are unloaded as well. It was as if the two held the same data.

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

Upvotes: 3

Views: 8027

Answers (1)

Andrew Russell
Andrew Russell

Reputation: 27235

There is nothing wrong with the code you have posted. Personally I use Game.Services - but Content.ServiceProvider is fine too - they both point at exactly the same object.

The bug must be elsewhere in your code. Are you absolutely sure you are using the correct content manager in each case?

Have you tried stepping through your code in the debugger? And making use of the "Make Object ID" function? (In the context menu for watch variables or variables that you mouse-over.)

Upvotes: 4

Related Questions