#Multiple fields in a single Component?

1 messages · Page 1 of 1 (latest)

hollow harbor
#

Is it bad to have multiple pieces of data inside a single component in Unity DOTS?

For example: MovementIsActive, MovementSpeed, and MovementTargetPosition.

All of them are movement-related data. Should I separate them, or is it okay to have them in a single component?

spare mantle
#

depends on how data is used: how many jobs read certain field, how many write

#

if you have everything in one component

#

that means any RW job will have to wait

#

for any other job

#

while if you split

#

and some jobs only RO some other field

#

your RW job may still run

native narwhal
#

Pretty much exactly what's said above. The ideal granularity for an ECS component is the smallest amount of data needed by any particular job. If most of your jobs need fields A/B/C but one of them only needs A/B, then maybe consider splitting field C into a separate component.

#

Taken to extremes, that means every field of every component should be its own component -- we should have PositionX, PositionY, PositionZ, etc. I don't think anybody's endorsing that as a real solution.