Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 emerz210 · Oct 08, 2019 at 08:54 PM · dots

ECS/Dots: How do get combined data of component values/make this accessible to all entities?

I have lots of components that all have a float3 position property. I want the combined float3 of all of the components to be able to calculated, and I want the "combined positions" float3 to be accessible from all of the entities. How to do this?

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

2 Replies

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

Answer by andrew-lukasik · Nov 18, 2020 at 12:48 PM

Idea is to schedule jobs in such a way that you pass this data down the dependency stream:

 public class CalculateAveragePositionSystem : SystemBase
 {
     EntityQuery _query;
     NativeArray<float3> _averagePosition;
     protected override void OnCreate ()
     {
         _query = EntityManager.CreateEntityQuery(
                 ComponentType.ReadOnly<AveragePositionSrc>()
             ,    ComponentType.ReadOnly<LocalToWorld>()
         );
         _averagePosition = new NativeArray<float3>( 1 , Allocator.Persistent );
     }
     protected override void OnDestroy ()
     {
         _averagePosition.Dispose();
     }
     protected override void OnUpdate ()
     {
         NativeArray<LocalToWorld> ltrArray = _query.ToComponentDataArray<LocalToWorld>( Allocator.TempJob );
         var averagePosition = _averagePosition;// alias
         Job
             .WithName("calculate_sum_job")
             .WithDisposeOnCompletion( ltrArray )
             .WithCode( ()=>
             {
                 float3 vec = default(float3);
                 for( int i=0 ; i<ltrArray.Length ; i++ )
                     vec += ltrArray[i].Position;
                 vec /= (float)ltrArray.Length;
                 averagePosition[0] = vec;
             } )
             .WithBurst().Schedule();
         
         Entities
             .WithName("do_something_with_that_data_job")
             .WithReadOnly( averagePosition )
             .ForEach( ( ref AveragePositionDst averagePositionMarker ) =>
             {
                 averagePositionMarker.Value = averagePosition[0];
             } )
             .WithBurst().ScheduleParallel();
     }
 }
 
 public struct AveragePositionSrc : IComponentData {}
 public struct AveragePositionDst : IComponentData { public float3 Value; }
Comment
Add comment · Show 1 · 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 PincerGame · Nov 23, 2020 at 08:59 AM 0
Share

Ah okay! I see, thanks for the answer

avatar image
0

Answer by PincerGame · Nov 18, 2020 at 10:24 AM

Hello @emerz210, to combine multiple queries, you can pass an array of EntityQueryDesc. Check the below code example. The following example selects any archetypes that contain a RotationQuaternion component or a RotationSpeed component (or both):

 var desc1 = new EntityQueryDesc
 {
     All = new ComponentType[] { typeof(RotationQuaternion) }
 };
 
 var desc2 = new EntityQueryDesc
 {
     All = new ComponentType[] { typeof(RotationSpeed) }
 };
 
 EntityQuery query
     = GetEntityQuery(new EntityQueryDesc[] { desc1, desc2 });

Comment
Add comment · Show 1 · 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 andrew-lukasik · Nov 18, 2020 at 10:54 AM 0
Share

This is a good answer for some very different question.


He wants to sum float3 values. Not merge EntityQuery instances.

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

112 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

Related Questions

Label dots in between numbers (currency formatting) 2 Answers

How can I get a component data from an entity inside a JobComponentSystem? 1 Answer

Instantiated prefab missing ECS components 1 Answer

Will Allocator.Temp erase contents of my native containers? 1 Answer

Where is com.unity.animation? 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