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. Dismiss Notice

Resolved Are Entities including Component "Prefab" automatically excluded from queries?

Discussion in 'Entity Component System' started by Samsle, Aug 5, 2023.

  1. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    103
    I have a component with the name "EntityNameComponent", which will be attached to certain entities via authoring (baker).

    A system named "SetEntityNameSystem" is doing a query over these components and it shows 0 Entities. This makes sense, since this system removes the component from the entity again.
    upload_2023-8-5_9-16-59.png

    But at the same time, if I do a Component Query via Inspector, it tells me that there are 38 Entities.
    (Worth noting: All of these entities have the component (tag) "Prefab" attached to them)
    upload_2023-8-5_9-17-43.png

    I mean, it makes sense that in most cases I don't want to query the prefab entities, but it makes the inspection confusing. Imho there should be "Prefab" listed as excluded. Also, what if I want to query the prefab entities? It feels like I don't have control over my entities..
     
    Last edited: Aug 5, 2023
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,556
    Inspector is correct. Systems ignores prefabs by default. But you have multiple entities with given components.

    Yes, prefab entities are excluded from usual jobs queries. Unless you specify otherwise.

    In the end, you usally don't want move, rotate or manipulate on prefabs. Unless during prefabs creation. Consider for example projectile prefab, where you spawn tons of projectiles none stop, during gameplay.

    You may want to include specifically prefab component in a query. This way you filter them specifically. Also, you can cache prefabs references in a singleton, or some other collection, if you wish.
     
    Samsle likes this.
  3. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    103
    Thanks for the confirmation!
    But then I think they should display it in a better way -making it clear that both are indeed "not" the same query, the other one just hides a default exclude.

    Like you said I usually have prefabs references in a singleton, but still good to know, thx :)
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    EntityQueryBuilder also has .WithOptions(EntityQueryOptions.IncludePrefab) to include such entities.
     
    Antypodish and Samsle like this.