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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question Access Components in Trigger/Collision Jobs

Discussion in 'Entity Component System' started by andreyakladov, Apr 2, 2023.

  1. andreyakladov

    andreyakladov

    Joined:
    Nov 11, 2016
    Posts:
    29
    Is there a (better) way to access components inside ITriggerEventsJob/ICollisionEventsJob than having this:
    Code (CSharp):
    1. public partial struct EffectsTriggerSystem : ISystem
    2. {
    3. [ReadOnly] private ComponentLookup<Parent> _lookupParent;
    4. [ReadOnly] private ComponentLookup<PowerUpData> _lookupPowerUp;
    5. [ReadOnly] private ComponentLookup<EffectSpeed> _lookupEffectSpeed;
    6. [ReadOnly] private ComponentLookup<EffectDamage> _lookupEffectDamage;
    7. [ReadOnly] private ComponentLookup<EffectBoostXP> _lookupEffectXPBoost;
    8. [ReadOnly] private ComponentLookup<EffectRegenHP> _lookupEffectRegenHP;
    9. [ReadOnly] private ComponentLookup<EffectRegenArmor> _lookupEffectRegenArmor;
    10. [ReadOnly] private ComponentLookup<EffectShield> _lookupEffectShield;
    Can I work with Triggers inside ISystem/SystemBase without a job?
    Is this approach not-too-much-worse performance-wise (having generic System and Job):
    Code (CSharp):
    1. public partial struct EffectTriggerSystem<T> : ISystem where T: unmanaged, IEffectTimed
    2. {
    3.    [ReadOnly] private ComponentLookup<Parent> _lookupParent;
    4.    [ReadOnly] private ComponentLookup<PowerUpData> _lookupPowerUp;
    5.    [ReadOnly] private ComponentLookup<T> _lookupEffect;
    6. ...