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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Feature Request Add `HasAspect<T>(Entity)`

Discussion in 'Entity Component System' started by Enderlook, Apr 27, 2023.

  1. Enderlook

    Enderlook

    Joined:
    Dec 4, 2018
    Posts:
    44
    At the moment there are no APIs to know if an entity satisfies an aspect or not.
    Currently, the only form of knowing if an entity has an aspect is by iterating over each component required by the aspect and checking if the entity has it or no, which is... unfortunate.
    I propose adding:
    Code (CSharp):
    1. EntityManager.HasAspect<T>(Entity)
    2. SystemAPI.HasAspect<T>(Entity)
    Also, TryGet APIs for aspects and components won't be bad either...
     
    apkdev, mrbinggrae and desper0s like this.
  2. jhelbig

    jhelbig

    Joined:
    Jul 25, 2019
    Posts:
    6
    I agree, also Aspect.Lookup should offer this functionality like ComponentLookup does.
    Another workaround is to create an EntityQuery for the Aspect and use EntityQuery.Matches() to check if an Entity has that Aspect.
     
    apkdev likes this.
  3. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Since Aspects are pretty much only codegen magic, I imagine an API like that would not be any faster than actually checking each component, since that would be happening under the hood anyway.
    But I totally agree that it would still be very convenient! The dev team has said in the past that Aspects are still a WIP and that their API would be expanded over time. I mean, not even the devs are using Aspects from what I can tell (TransformAspect was removed last patch because it didn't really serve a purpose anymore). Hopefully that can change in the 1.0 Release or perhaps soon after that, because Aspects can heavily decrease the amount of boilerplate in some situations (like checking for many components' required or optional existence over and over).

    Another request I would add is the support of optional EnabledRefRO/RW fields. They are currently broken, and the devs know this (someone reported that a few months ago), yet it still hasn't been fixed. I hope it's still on their radar.
     
    apkdev likes this.