Is there any alternative to load content in MonoGame?

Hello guys.

I’m trying to port my libgdx based game engine to monogame and I’m having problems with the monogame content Pipeline.

You see, I’m a visual disabled user, then in order to work in a computer i must use a screen reader.
My screen reader is called NVDA https://www.nvaccess.org/
And it seems that the monogame content Pipeline it’s not 100% NVDA friendly.

Then, I was wondering if there’s any alternative to load content.
Maybe a non GUI based content Pipeline, you know, like a cmd version.
Or maybe some way to load the content directly, like libgdx does.

I’ll really appreciate any suggestions.
Thanks in advance.

You can use FromStream and feed it a FileStream and it will load it from disk:

This works with other types of assets as well such as sound and music.
such as this:

                imageFile = new System.IO.FileStream(p_imageFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                Image = Texture2D.FromStream(p_graphicsDevice, imageFile);

                imageFile.Close();
                imageFile = null;
1 Like

The .mgcb file can be edited entirely in a text editor and built from the command line. The Pipeline tool is only a UI tool to edit the text file and trigger the build process. If you read the MGCB doc page it has a decent list of some of the options in the .mgcb, but it doesn’t list all the available importers and processors and their parameters such as ResizeToPowerOfTwo and PremultiplyAlpha. You could find all those options as public properties in the processors’ source code, but it might be tedious to check each one. That is, of course, the point of the UI tool, which I’m sorry isn’t very accessible.

I almost never use the content pipeline. I use this to load sprites/textures:

private Texture2D LoadFromFile(string filename)
{
using (var stream = File.OpenRead(filename))
{
return Texture2D.FromStream(_graphicsDevice, stream);
}
}

For sound I always use FMOD integration, so I don’t know the standard Monogame way. But I’m sure there is a similar way to load sound files.

For structured data I use POCO’s and serialize them to and from JSON text files so they’re easy to edit. (I use nuget package NewtonSoft.Json and use JsonConvert.SerializeObject and DeserializeObject)

Small remark: you should use the using pattern which calls .Dispose() on your stream when imageFile goes out of scope. When doing it like your code, the resources behind your stream are not cleaned up if the FromStream statement throws an exception.

That code is in a Try Catch, but the using is a bit cleaner, so I switched it to that.

Thanks a lot for all your answers.
I’ll give both suggestions a try.

I’ve hear that the content pipeline is recommended because it handles all the cross platform compatibility stuff.
Do you guys think that I should attem to deal with the .mgcb file manually?

For cross platform, you should go with the content pipeline yes.

But, I try to stick to solving only the problems that really need solving at a given time. Most game projects take a LOT more effort than initially assumed (and often never get published), so it’s best to not try and solve all your potential problems from the start, because then you’re never done. You’d also do a lot of stuff prematurely while later on it turns out you didn’t need it or it had to be done differently.

So, if the pipeline is giving you a hard time, postpone that problem until it is really necessary to solve… Unless it is really necessary to solve right now, of course :slight_smile: