Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

ComponentDataFromEntity by ref

Discussion in 'Data Oriented Technology Stack' started by sebas77, Jun 29, 2020.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    Is there any specific reason why ComponentDataFromEntity cannot return by ref and if there isn't, can it be changed? At glance, it looks like a simple win.
     
    ExtrysGO and M_R like this.
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,061
    ComponentDataFromEntity is a native container which itself only store pointer (and 3 utility fields and 2 of them even readonly), what is the point getting it by ref?
     
  3. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    maybe I wasn't c lear, but I meant getting the entities components from it by ref.
     
  4. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    537
    probably safety, there is currently nothing that would prevent
    Code (CSharp):
    1. ref var data = cdfe[myEntity];
    2. EntityManager.AddComponent(myEntity, new StructuralChange());
    3. data.value++; // BOOM
     
    ExtrysGO likes this.
  5. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    Your example makes sense.

    Those kinds of structural changes shouldn't happen at any time, it's a flaw in the entity manager design.
     
    Last edited: Jun 29, 2020
    ExtrysGO and burningmime like this.
unityunity