Search Unity

[Bug] with enum member in IComponentData

Discussion in 'Entity Component System' started by Spy-Shifty, Sep 26, 2018.

  1. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    This is weird.
    The data of Team.value changes when I add a component to the entity by EndFrameBarrier.EntityCommandBuffer

    Before adding: Team.value = TeamValues.White
    After adding: Team.value = TeamValues.Black

    Code (CSharp):
    1. [Inject] EndFrameBarrier endFrameBarrier;
    2.  
    3. SomeJob.CommandBuffer = endFrameBarrier.CreateCommandBuffer().ToConcurrent(),
    4.  
    5. //Inside somejob...
    6. CommandBuffer.AddComponent<Selected>(0, entity); // extension method...

    Code (CSharp):
    1. public enum TeamValues {
    2.     Black = 0,
    3.     White = 1,
    4. }
    5.  
    6. [Serializable]
    7. public struct Team : IComponentData {
    8.     public TeamValues value;
    9. }
    10.  
    11. [DisallowMultipleComponent]
    12. public class TeamComponent : ComponentDataWrapper<Team> { }

    Appendix:
    Code (CSharp):
    1.     public static void AddComponent<T>(this EntityCommandBuffer.Concurrent entityCommandBuffer, int jobIndex, Entity entity) where T : struct, IComponentData {
    2.         entityCommandBuffer.AddComponent(jobIndex, entity, new T());
    3.     }
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    But where you set enum? And what is Selected type? And which version of ECS.
     
  3. gebbiz

    gebbiz

    Joined:
    May 23, 2018
    Posts:
    14
    If you are using entities preview.15 adding empty components using command buffer causes data corruption. "Selected" is probably an empty tag component?
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Yeah as @gebbiz says if "Selected" is tag and you use latest package is broke data.
     
    Spy-Shifty likes this.
  5. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    The enum is setted up on instantiating the Gameobject (prefab)

    Yes Select is a "Tag type" -> struct Selected : IComponentData { }

    Version: 0.0.12-preview.15
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    And this answer for your question :)
     
  7. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Is there a work around?
     
  8. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Is the entity you added happened to be zero-sized? There is a bug that zero-sized component added via ECB will destroy other entities data : P

    The work around is adding a field to your zero-sized component
    int notzerolol;
    then you can search & replace with blank later.

    My issue : https://forum.unity.com/threads/component-data-with-half-value-is-bugged-right-now.560059/ but it only corrupts when the data is in a weird size (half got corrupted by zero-sized component, but int did not)
     
    eizenhorn and Spy-Shifty like this.
  9. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Yes his Selected is empty zero sized tag
     
  10. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546

    That was what I thought to....

    So my solution:

    Code (CSharp):
    1. struct Selected : IComponentData {
    2.      public int bugfix;
    3. }
     
  11. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Yes now is only way :)

    upload_2018-9-26_12-1-20.png
     
    Spy-Shifty likes this.
  12. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684