Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 pastersteli · Aug 03, 2021 at 11:16 PM · dots

Entity system following an object

I have many object to follow a main object. Is there way to easily access position of entity or find the entity from code Here is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 using Unity.Entities;
 using Unity.Jobs;
 using Unity.Mathematics;
 using Unity.Physics;
 using Unity.Transforms;
 using Unity.Burst;
 
 [BurstCompile]
 [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
 public class BallFollowController : SystemBase
 {
 
     /*
     protected override JobHandle OnUpdate(JobHandle inputDeps)
     {
         float deltaTime = Time.DeltaTime;
 
         Entities.ForEach((ref Translation translation, in BallMainData data) => {
             //translation.Value.z += data.speed * deltaTime;
             temp = translation.Value;
         }).Run();
         var jobHandle = Entities.ForEach((ref PhysicsVelocity velocity,in Translation translation, in BallFollowData data) => {
             velocity.Linear += (temp - translation.Value)*data.speed*deltaTime;
 
         }).Schedule(inputDeps);
         
     }
     */
     protected override void OnUpdate()
     {
         float deltaTime = Time.DeltaTime;
 
         
         Entities.ForEach((ref PhysicsVelocity velocity, in Translation translation, in BallFollowData data) => {
             float3 temp = new float3();
             Entities.ForEach((ref Translation translation, in BallMainData data) => {
                 //translation.Value.z += data.speed * deltaTime;
                 temp = translation.Value;
             }).Run();
             velocity.Linear += (temp - translation.Value) * data.speed * deltaTime;
 
         }).Schedule();
     }
 }
 
Comment
Add comment · Show 2
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 pastersteli · Aug 04, 2021 at 12:39 AM 0
Share
 'BallFollowController' is missing the class attribute 'ExtensionOfNativeClass'!





avatar image andrew-lukasik · Aug 04, 2021 at 05:18 AM 0
Share

'BallFollowController' is missing the class attribute 'ExtensionOfNativeClass'!

This error is caused by misplaced [BurstCompile] attribute, remove it.

[BurstCompile] belongs to very specific structs not classes.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andrew-lukasik · Aug 04, 2021 at 07:14 AM

 using Unity.Entities;
 using Unity.Jobs;
 using Unity.Mathematics;
 using Unity.Physics;
 using Unity.Transforms;
 using Unity.Collections;
 
 [UpdateInGroup( typeof(FixedStepSimulationSystemGroup) )]
 public class BallFollowerSystem : SystemBase
 {
     EntityQuery _query;
 
     protected override void OnCreate ()
     {
         _query = EntityManager.CreateEntityQuery( typeof(Translation) , typeof(BallMainData) );
     }
 
     protected override void OnUpdate ()
     {
         float deltaTime = Time.DeltaTime;
         var mainBallPositions = _query.ToComponentDataArray<Translation>( Allocator.TempJob );
         
         Entities
             .WithReadOnly( mainBallPositions ).WithDisposeOnCompletion( mainBallPositions )
             .ForEach( ( ref PhysicsVelocity velocity , in Translation translation , in BallFollowData data ) =>
             {
                 for( int i=mainBallPositions.Length-1 ; i!=-1 ; i-- )
                 {
                     float3 ballPos = mainBallPositions[i].Value;
                     float3 ballDir = math.normalize( ballPos - translation.Value );
                     velocity.Linear += ballDir * data.speed * deltaTime;
                 }
             } )
             .WithBurst()
             .ScheduleParallel();
     }
 
 }
Comment
Add comment · Show 4 · 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 pastersteli · Aug 04, 2021 at 08:57 AM 0
Share

When I make them systembase, I dont need to attach them an object ? Are they running automaticly?

avatar image andrew-lukasik pastersteli · Aug 04, 2021 at 11:28 AM 1
Share

Basically, yes. Entities.ForEach creates matching EntityQuery, behind the scenes, and this EnityQuery thing is kind of a filter that selects matching entity data collections (chunks) for which for code will be executed.

This means that your Entities.ForEach code will execute only when matching entities exists.

avatar image pastersteli andrew-lukasik · Aug 04, 2021 at 04:45 PM 0
Share

Thanks for helping... Can u look my new question? And Do u have any suggestion to learn this stuffs?

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.

Follow this Question

Answers Answers and Comments

123 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

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 make singleplayer/multiplayer game with DOTS 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