• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by benapprill · Dec 15, 2020 at 07:51 AM · dots

Using multiples queries, in the same update loop. Unity ECS

I am trying to check the range of entities with a certain tag, from entities with a different tag.

If I use two separate queries to gather the different types of entities, I am not sure if re-gathering the query every frame is inefficient or not.

To deal with that, I can move the queries to the OnCreate(), or OnStartRunning() handles.

However, does this mean the query only has the members at that capture time? Or do the queries automatically handle updating somehow... Or, do I need to consider something else.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by andrew-lukasik · Dec 15, 2020 at 08:26 AM

EntityQuery needs no updates, because:

An entity query defines the set of component types that an archetype must contain in order for its chunks and entities to be selected (...)

and:

(...) and specifies whether the components accessed through the query are read-only or read-write.

So, fundamentally, this is all what EntityQuery is: a collection of requirements to filter/select chunks - you don't have to update it if you don't want to. It's something of a key with which one can iterate over specific chunks to access their data and this key stays valid while chunks it selects change.


 public class MySystem : SystemBase
 {
     EntityQuery _query1;
     EntityQuery _query2;
     protected override void OnCreate ()
     {
         _query1 = EntityManager.CreateEntityQuery(
                 ComponentType.ReadOnly<MyComponent>()
         );
         _query2 = EntityManager.CreateEntityQuery(
                 ComponentType.ReadWrite<MyComponent>()
             ,    ComponentType.ChunkComponent<MyChunkyComponent>()
             ,    ComponentType.Exclude<MyNahComponent>()
         );
     }
     protected override void OnUpdate ()
     {
         /* queries will always be up-to-date here */
     }
 }
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image benapprill · Dec 15, 2020 at 10:03 PM 0
Share

A question to clarify.

If new entities are added that match the query archetype, are these also automatically updated, without calling the query again in the update loop?

avatar image andrew-lukasik benapprill · Dec 15, 2020 at 11:19 PM 0
Share

Define "calling the query"

avatar image benapprill benapprill · Dec 16, 2020 at 12:37 AM 0
Share

Having to update the query inside the update loop, in order to get newest information on existing entities.

In instances with a single query, it is easy enough to assign some kind of change filter to reduce calls. However, with the second query involved, I am not sure how to gather that information, without making the query update each frame...

avatar image andrew-lukasik benapprill · Dec 16, 2020 at 12:36 PM 0
Share

EntityQuery needs no updates, because:

An entity query defines the set of component types that an archetype must contain in order for its chunks and entities to be selected (...)

and:

(...) and specifies whether the components accessed through the query are read-only or read-write.

So, fundamentally, this is all what EntityQuery is: a collection of requirements to filter/select chunks - you don't have to update it if you don't want to. It's something of a key with which one can iterate over specific chunks to access their data and this key stays valid while chunks it selects change.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[ECS] Create Entities from Job ( IJobForEachWithEntity) using an EntityCommandBuffer 1 Answer

Best way to get data from a Monobheaviour in a JobComponentSystem? 2 Answers

[ECS] DefaultWorldInitialization.Initialize take 50MB 1 Answer

Unity (ECS & DOTS) Entity Sinking 0 Answers

How to create realistic wire 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges