Search Unity

Should I use inheritance in components

Discussion in 'Entity Component System' started by muzappar2, Aug 6, 2019.

  1. muzappar2

    muzappar2

    Joined:
    Jun 27, 2017
    Posts:
    8
    Like this:

    PComponent : IComponentData
    AComponent : PComponent
    BComponent : PComponent

    then use them in some systems:

    PSystemJob : IJobForEach<PComponent>
    ASystemJob : IJobForEach<AComponent>

    Etc.
     
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    You can not use inheritance as IComponentData has to be a struct.
     
  3. muzappar2

    muzappar2

    Joined:
    Jun 27, 2017
    Posts:
    8
    Oh sorry I forgot that the component is a struct.
    And is there any way to implement that?
     
  4. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    PComponent : IComponentData
    AComponent : IComponentData
    BComponent : IComponentData

    PSystemJob : IJobForEach<PComponent>
    ASystemJob : IJobForEach<PComponent, AComponent>
    BSystemJob : IJobForEach<PComponent, BComponent>
     
  5. muzappar2

    muzappar2

    Joined:
    Jun 27, 2017
    Posts:
    8
    Thanks a lot.