New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with Multiple Mgcb's #4977
Comments
Why do you use two different .mgcb files? |
I was experimenting with the idea of being able to have seperate .mgcb files for a variety of reasons, here is some of my thinking: If I am creating a re-usable library (I'd like to use for multiple different game projects) - let's say it a screen management system - i.e it displays windows, and the library needs to load some content like a background for the windows, and some fonts etc. If distribute the library with its own Such a re-usable library could be distributed via a NuGet package, containing the assembly and a custom install.ps1 script that adds a reference to the I noticed also that |
This is a very common scenario and pretty much how any large game used to |
I used to work with multiple ContentManager as well, but I ended up extending it with tags (i.e. Load() accepts optional tags, as well as Unload(), to unload only a specific assets category). |
To be clear... MonoGame supports having multiple The issue here in our .targets file: It assumes a single content root no matter the number of .mgcb files. Instead it should be depending on the content root defined within the .mgcb... but the problem is that the .target wouldn't then know were to place the final content. This process just needs a refactor. |
@tomspilman I'd be up for having a go with this, i am quite familiar with msbuild, but i'm new to monogame so would need guidance in particular areas.
Is there a way to read the Assuming we can get to that setting, would the following be basically what we are after: For each
Formulate the This would mean making multiple I'm probably not best placed to pick this work up but I will give it a go in anyone elses absence! |
I don't think that the mgcb output folder can be used for this, it can be set to something unrelated to content root and obj folder. I believe a dedicated parameter would be better if we'd like to make it clean, or maybe inferring the root based on the .mgcb relative path to ProjectDir. |
Ah ok. All we need is for the content from different mgcb's to end up in different directories rather than all in the same /Content folder. So we could just use |
What I was thinking about, is to use the .mgcb's path to define where xnb's are copied, e.g.:
I believe this would feel natural to users because virtually anything you put in a project folder (being xnb's or non-pipeline files) would end up in the destination you would expect from your project setup in a similar way to the "copy to output" build action. |
@mrhelmut - got ya! Yep that makes sense to me. |
Ok, so I have the solution open, and I am making changes to the .targets file. Would appreciate any guidance on the best way is to test it? Am thinking I should just manually create a new monogame project, swap the targets file out in it's .csproj, add some |
Yeah... that is really the only option. We don't have any sort of unit testing of the template projects. I would love to fix that some day, but so far no one has stepped up with a solution to that. |
Modified msbuild targets file, so that when mgcb's are built, their build output is copied to a directory in the output folder that is relative to the path of the mgcb within the project. This allows content to more easily be isolated by moving mgcb's to seperate prokected folders.
No problem, will test manually. PR is on its way! |
PR submitted, which makes the following come true:
So the xnb's will now appear in an output folder that is relative to the However am left with some questions now about loading content at runtime. Given the structure above, what happens if when your game runs you create a new What happens if you create two |
Absolutely. They don't affect each other, but you may end up loading the same asset twice, once in one ContentManager instance and again in the other ContentManager instance if you loaded "Sub/Asset" in one and "Asset" in the other. They don't know about each other, so the same asset is loaded twice. It all comes down to how you plan your assets. It's your choice if you want nested ContentManagers like that. |
Cool - sounds good to me then ;) |
PR was submitted for this: #4997 |
* Fixes MonoGame#4977 Modified msbuild targets file, so that when mgcb's are built, their build output is copied to a directory in the output folder that is relative to the path of the mgcb within the project. This allows content to more easily be isolated by moving mgcb's to seperate prokected folders. * Removed a comment line I had accidentally left in. * Fixed issue where xnb's relative directory was not preserved when output to the bin folder. * Now also supports linked mgcb files. * Removed whitespace. Fixed a problem with a missing condition, causing more output than necessary. * Removed additional backslahes.
Hello,
I am attempting to split out some content so I can use 2 seperate
ContentManager
instances.I assumed if I referenced two seperate
mgcb
files from my project, that I could get them to output their content to different directories when I build my project.When creating a
ContentManager
you need to give it a root directory, so I assumed I could create one for each content directory where mymgcb
content is output:The problem is, when I build the project, the assets from the multilple referenced
mgcb
s are always output directly to thecontent
folder under py projects output directory. Furthermore, the 1st output is cleared when the 2ndmgcb
is built, and so I actually only end up with the content of the 2ndmgcb
file in by output directory.Here is how it looks (note I added the
mgcb
files usingAdd as Link
It doesn't seem to matter which folder in my project that I add the reference to the
mgcb
too, when I build they always seem to output to the outputDir/Content folder for my project.This means I don't end up with seperate root paths to create my ContentManager instances for, and also the build clearing the content output by the first mgcb when it builds the second one is obvioulsy a bit problematic!
Any ideas?
The text was updated successfully, but these errors were encountered: