Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Disabled Component need ecb to work? and Crash when using Add/RemoveChunkComponentData<Disabled>()

Discussion in 'Entity Component System' started by tassarho, Jul 8, 2022.

  1. tassarho

    tassarho

    Joined:
    Aug 25, 2019
    Posts:
    64
    i encounter 2 suspicious behaviours:

    1) when Adding the component Disabled without using Entity command buffer, the entity is still rendered:
    Code (CSharp):
    1. EntityManager.AddComponent<Disabled>(entityQuery);
    2) i wanted to reproduce the bug using Disabled as a chunkComponentData but Unity crash when passing to the following method:

    Code (CSharp):
    1. for (int i = 0; i < regimentToUpdate.Length; i++)
    2.             {
    3.                 preselectionHighlightQuery.SetSharedComponentFilter(new RegimentSharedData(){Regiment = regimentToUpdate[i]});
    4.                 if (regimentToUpdateState[i])
    5.                 {
    6.                     EntityManager.RemoveChunkComponentData<Disabled>(preselectionHighlightQuery);
    7.                 }
    8.                 else
    9.                 {
    10.                     //CAREFULL: with Disable, we need to use an ecb
    11.                     //otherwise, the renderer seems to not know the entity should not be rendered
    12.                     EntityManager.AddChunkComponentData(preselectionHighlightQuery, new Disabled());
    13.                 }
    14.                 preselectionHighlightQuery.ResetFilter();
    15.             }
    Are those behaviours normal or am i juste using both disable and chunkComponent the wrong way?

    EDIT: it seems the point 1) doesn't apply to DisableRendering
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    You're using AddChunkComponentData not AddComponentData.

    I'm really not surprised that trying to add disabled as a chunk component makes it crash.
     
  3. tassarho

    tassarho

    Joined:
    Aug 25, 2019
    Posts:
    64
    I actually added it as a chunkComponentData

    Code (CSharp):
    1. public class DisabledAtSpawn : MonoBehaviour, IConvertGameObjectToEntity
    2. {
    3.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    4.     {
    5. dstManager.AddChunkComponentData<Disabled>(entity);
    6.     }
    7. }
    it doesn't crash at this moment and the component was added on the entities, it's when i tried to manipulate them the editor crash
     
    Last edited: Jul 8, 2022
  4. Elapotp

    Elapotp

    Joined:
    May 14, 2014
    Posts:
    98
    If you use EntityManger, there is a helper method SetEnabled.

    Are you sure that Disabled component does not influence Rendering?
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    Don't use chunk components for this. Nothing in Unity is prepared for or expects either Disabled or DisableRendering to be a chunk component.

    However, that non-responsiveness to Disabled for rendering is likely a bug. It seems anything relying on chunk component iteration will miss that. I probably have similar bugs in my own code.
     
    tassarho likes this.
  6. tassarho

    tassarho

    Joined:
    Aug 25, 2019
    Posts:
    64
    i wish i could use SetEnable, but unfortunately there is no overload using entityquery, and yes Disable influence Rendering but seems to only work when using an entity command buffer.