Hello,
I am pretty new to game programming, and am trying my best to build a little ECS engine just to get some basics correctly.
The ECS simply loads an XML file (a basic XnaContent type file) with Monogame’s Content Pipeline, and adds a few objects into an array.
Everything works fine, except when I add a public ( or event private) TiledMap property to one of my components (which is then loaded in the XML file specified above). Then the Content Importer throws an error that I cannot understand. The error says: Microsoft.Xna.Framework.Content.Pipeline.InvalidContentException: Type 'ProjectRabbit.ECS.Components.TiledMapComponent' is not assignable to 'ProjectRabbit.ECS.Components.BaseComponent'.
As soon as I remove the TiledMap property, everything builds fine. I have tried to use the ContentSerializerIgnore attribute, and it doesn’t change anything.
Any help is appreciated, thank you in advance !
Here is a sample of my XML file:
<?xml version="1.0" encoding="UTF-8" ?>
<XnaContent>
<Asset Type="System.Collections.Generic.Dictionary[ProjectRabbit.ECS.Entity, ProjectRabbit.ECS.Components.BaseComponent[]]">
<Item>
<Key><ID>1</ID></Key>
<Value>
<Item Type="ProjectRabbit.ECS.Components.PositionComponent"></Item>
<Item Type="ProjectRabbit.ECS.Components.SpeedComponent">
<Speed>0 0</Speed>
</Item>
<Item Type="ProjectRabbit.ECS.Components.SpriteComponent">
<SpriteName>Sprites/obama_sprite</SpriteName>
</Item>
<Item Type="ProjectRabbit.ECS.Components.PlayerControlledComponent">
<Speed>2.5</Speed>
</Item>
<Item Type="ProjectRabbit.ECS.Components.MapLayerComponent">
<LayerIndex>1</LayerIndex>
</Item>
</Value>
</Item>
<Item>
<Key>
<ID>2</ID>
</Key>
<Value>
<Item Type="ProjectRabbit.ECS.Components.TiledMapComponent">
<MapName>Tiled/map1</MapName>
</Item>
</Value>
</Item>
</Asset>
</XnaContent>
And here the “TiledMapComponent” that breaks everything:
using System;
using Microsoft.Xna.Framework.Content;
using MonoGame.Extended.Maps.Tiled;
namespace ProjectRabbit.ECS.Components
{
public class TiledMapComponent: BaseComponent
{
public String MapName;
private TiledMap TiledMap;
public TiledMapComponent ()
{
}
public TiledMapComponent (String MapName)
{
this.MapName = MapName;
}
public void SetTileMap(TiledMap Map)
{
this.TiledMap = Map;
}
public TiledMap GetTileMap()
{
return this.TiledMap;
}
}
}