I ran into some trouble when with the Content.Load<T>(string assetName)
function, when trying to load files from directories given relative to the ContentRootDirectory
.
Let’s say I have an *.xnb file for a SpriteFont
, font.xnb, which I compiled with the MonoGame Content Pipeline. My ContentRootDirectory
is found under “Debug(Release)/Content”. Using
SpriteFont font = Content.Load<SpriteFont>("font");
works fine. Also giving an absolute path, e.g.,
SpriteFont font = Content.Load<SpriteFont>(@"C:/assets/fonts/font");
results in loading of the file. However, when using relative path statements, such as
SpriteFont font = Content.Load<SpriteFont>(@"../../../fonts/font");
I get the message “Could not load …/…/…/fonts/font asset as a non-content file”. Interestingly, things like
SpriteFont font = Content.Load<SpriteFont>(@"../Content/font");
are working, but, again,
SpriteFont font = Content.Load<SpriteFont>(@"../../Debug/Content/font");
is not. I am rather confused about this behavior.