Hi,
I’m having a problem loading an asset of a custom content type exported by the monogame pipeline tool.
These are the steps that I followed:
Converted the SpriteSheetPipeline processor to work with monogame
Added compiled library to MonoGame Pipeline
Added assets in MonoGame Pipeline
Changed the assets’ processor to SpriteSheetPipeline
When loading them in the game I get the following exception:
Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: Microsoft.Xna.Framework.Content.ArrayReader1[[Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2DContent, MonoGame.Framework.Content.Pipeline, Version=3.4.0.456, Culture=neutral, PublicKeyToken=null]] (Microsoft.Xna.Framework.Content.ArrayReader1[[Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2DContent, MonoGame.Framework.Content.Pipeline]])
It doesn’t feel like it’s pointing to my code so I’m not sure what I’m missing here.
Can someone point me out in the right direction to fix this issue?
The game project does not reference the content pipeline, so it cannot load an array of Texture2DContent. I think there are some fixes required in the ContentWriter part of the content pipeline extension.
Can you show the code for the SpriteSheetPipeline? It will likely need the GetRuntimeType and GetRuntimeReader methods of the ContentTypeWriter overridden to specify the runtime types.
With those methods overridden I get a cast exception when reading the asset:
spriteSheet.textures = input.ReadObject<Texture2D[]>();
produces:
Additional information: Unable to cast object of type ‘Microsoft.Xna.Framework.Graphics.Texture2D’ to type ‘Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2DContent’.
I was able to fix the problem by writing a count and each texture separately and have the reader do the reverse, read the count, instantiate the array of texture2d and read each texture2d to that array.
It seems like writing an array of textures is not supported out of the box.
This error seems like one caused by an issue I fixed some time back but the fix is still waiting to be merged. I’m not sure but it would be interesting to see if your original code works ok once this change set is applied (I can’t test it for a few days): https://github.com/mono/MonoGame/pull/3923
There are some problems with the current content pipeline build where it doesn’t always get all the required content reader types (particularly for generic types or arrays) written into the Xnb files.