Question by 
               downstroypvp · Dec 28, 2020 at 07:40 PM · 
                componentmanaged  
              
 
              [ECS] Error in EntityManager with managed IComponentData
When I try to add a managed IComponentData to an entity like this:
 World.DefaultGameObjectInjectionWorld.EntityManager.AddComponentData<StartingHandComponent>(entity, component);
 
               I get a :
 Entities = System.Runtime.InteropServices.MarshalDirectiveException: Type com.upgames.T9Aduel.StartingHandComponent which is passed to unmanaged code must have a StructLayout attribute.
 
               This is just a managed Component that contains scriptable objects that are required to initialize my entites. It is not used anywhere else beside here:
 NativeArray<Entity> entityWithStartingHands = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(PlayerComponent)).ToEntityArray(Allocator.Temp);
 NativeArray<GameStateComponent> gameStateComponents = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(GameStateComponent)).ToComponentDataArray<GameStateComponent>(Allocator.Temp);
 for (int i = 0; i  < gameStateComponents.Length; ++i)
 {
     GameStateComponent gsComponent = gameStateComponents[i];
     gsComponent.CurentStatus = GameStateComponentData.Status.Playing;
     gameStateComponents[i] = gsComponent;
 
     foreach (Entity entityWithStartingHand in entityWithStartingHands)
     {
         StartingHandComponent startingHandComponent = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentObject<StartingHandComponent>(entityWithStartingHand);
         foreach (EntityData entityData in startingHandComponent.CardDatas)
         {
             Entity card = entityData.CreateEntity();
                         World.DefaultGameObjectInjectionWorld.EntityManager.AddComponentData(card, new ControllerComponent(entityWithStartingHand));
         }
     }
 }
 gameStateComponents.Dispose();
 entityWithStartingHands.Dispose();
 
               If I comment the line with the AddComponentData, I don't get an error in the EntityManager, though it appears that the AddComponentData with a managed type is supported.
Does anyone have an idea?
               Comment
              
 
               
              Your answer