Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 daliksn · Apr 27 at 05:42 AM · systemdots

Entities outside SystemBase


Is it possible to list the entities I need with components via ForEachLambdaJobDescription Entities without the SystemBase class?


Let's say there is some event that enumerates entities only once in a lifetime, and calling onUpdate SystemBase every time sounds somehow too cumbersome.


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 · Apr 27 at 08:19 AM

Yes. You can query and grab whatever data you need, even from a common MonoBehaviour.


But be aware that everything Unity.Collections ( NativeArray<T> etc) will be slow to read/write outside a job. So still prefer jobs where possible (you can start them from Monobehaviours too)


 void Start ()
 {
     var world = World.DefaultGameObjectInjectionWorld;
     var entityManager = world.EntityManager;
 
     var query = entityManager.CreateEntityQuery(
         typeof(RenderBounds)
     );
     
     NativeArray<Entity> entities = query.ToEntityArray( Allocator.Temp );
     Entity[] entitiesArray = entities.ToArray();
     
     NativeArray<Entity> renderBounds = query.ToComponentDataArray<RenderBounds>( Allocator.Temp );
     RenderBounds[] renderBoundsArray = renderBounds.ToArray();
 }


Comment
Add comment · Show 3 · 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 daliksn · Apr 28 at 10:17 AM 0
Share

Thanks. Is it possible to achieve the same syntax as in Entities through a lambda instruction? And is it also a good practice from a performance point of view to create multiple arrays at once through ToComponentDataArray in order to work with several components at once through enumeration, and not with one?

avatar image andrew-lukasik daliksn · Apr 28 at 11:08 AM 0
Share


Is it possible to achieve the same syntax as in Entities through a lambda instruction?

Seems like a busywork, but syntax-wise - I can't see why not.

is it also a good practice from a performance point of view to create multiple arrays at once through ToComponentDataArray in order to work with several components at once through enumeration, and not with one?

Allocation time is rarely an issue, but when it becomes one - you can always use ToComponentDataArrayAsync instead of ToComponentDataArray.

More important thing: if you want anything here to be fast, your best choice is to create Burst-compiled jobs and schedule that. Everything else is low-performance, in comparison.


Sidenote: you don't want to enumerate any NativeArray<T> in Start (it's super slow).


avatar image daliksn andrew-lukasik · Apr 28 at 11:10 AM 0
Share

Thanks, I'll remember.

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.

Follow this Question

Answers Answers and Comments

136 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

Related Questions

Accessing local system ( File Browser ) 2 Answers

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

How can I change the button's color back to its previous state? 0 Answers

Randomly place a specific number of objects? 1 Answer

int.Parse(), float.Parse(), double.Parse() all not working when exported,int.Parse, float.Parse double.Parse all not working 1 Answer


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