Search Unity

Problems with ISharedComponentData

Discussion in 'Entity Component System' started by EvilWolf, Apr 15, 2018.

  1. EvilWolf

    EvilWolf

    Joined:
    Jan 19, 2014
    Posts:
    5
    Hey,

    I'm having some trouble with ISharedComponentData, not sure if I misunderstood how to use it.
    From what I understand, you want to use ISharedComponentData for data that will be the same in a lot of instances and does not change very often, but except for that it works largely like IComponentData.

    So, let's say I have a bunch of CollidableBoxes with only a Scale-parameter; loads of them will be standard 1x1x1 boxes but a few will have other values, so I figure ISharedComponentData is a good way to go. Whenever I create a box, I use SetSharedComponentData to set its scale. When I run the game, the EntityDebugger shows that the Scale for all boxes is 0, no matter what I initialise them with.

    Similarly, I thought I could use SharedComponentDataArray as parameters for jobs but I'm getting exceptions when I use those.

    It would be great if someone could clarify their purpose and maybe give an example on how to best use them.
    Thanks!
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Should normaly work...
    Maybe you can provide some code for us.

    SharedComponentDataArray must have the [ReadOnly] Attribute attached to it.
     
  3. trTribe

    trTribe

    Joined:
    Jun 8, 2017
    Posts:
    4
    I think that's a problem with the entity debugger, when I used ISharedComponentData for some int values it showed me some absurd random values, but printing them gave me the correct result, so I think that part is just a bug in the debugger window.