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 jmgek · Jan 04, 2019 at 12:08 AM · process

Scheduling a job issue

I'm trying to schedule a job for my ECS system, I'm following the docs on ECS docs specifically the handling of the job:

         protected override JobHandle OnUpdate(JobHandle inputDeps)
         {
             MovementJob moveJob = new MovementJob
             {
                 topBound = GameManager.GM.topBound,
                 bottomBound = GameManager.GM.bottomBound,
                 deltaTime = Time.deltaTime
             };
 
             JobHandle moveHandle = moveJob.Schedule(this, 64, inputDeps);
 
             return moveHandle;
         }

When trying to schedule this job on my own class I get this error: alt text even though the plant system derives from the job component system public class PlantSystem : JobComponentSystem

Full code:

 public class PlantSystem : JobComponentSystem
 {
     [Unity.Burst.BurstCompile]
     struct PlantJob : IJobProcessComponentData<Position, Plant>
     {
         public float health; 
         public void Execute(ref Position data0, ref Plant data1)
         {
             if(data1.health < 10000)
             {
                 float data2 = data1.health;
                 data1.health = data2 + 1;
             }
         }
     }
 
     protected override JobHandle OnUpdate(JobHandle inputDeps)
     {
         PlantJob plantJob = new PlantJob
         {
             health = 1.0f
         };
         return plantJob.Schedule(this, 64, inputDeps);
     }
 }

screenshot-1.png (20.5 kB)
Comment
Add comment · Show 5
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 jmgek · Jan 04, 2019 at 12:13 AM 0
Share

Okay return plantJob.Schedule(this, inputDeps); seems to work...

avatar image mjussila · Jan 08, 2019 at 05:29 AM 0
Share

I had exactly the same issue. Schedule(this, inputDeps) is indeed working, but it seems I'm losing all the ECS performance gains, having similar FPS to classic GameObject system. I think it might be that without that second argument 1 to 64 there is no parallel threads running. Haven't seen any clear answer to this yet. Did you get high FPS with these parameters?

avatar image jmgek mjussila · Jan 08, 2019 at 07:01 AM 0
Share

When using the ECS profiler are you able to see a list of all your entities?alt text @mjussila

screenshot-10.png (59.1 kB)
avatar image mjussila jmgek · Jan 08, 2019 at 10:46 AM 0
Share

Yes, I do see them, I'm running a test with 10000 simple spheres.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mjussila · Jan 08, 2019 at 08:22 PM

Well, now I'm testing with 10 000 simple spheres, and I noticed it makes a big difference to have the material checked with enable GPU instancing. With that on I get about 30 FPS with a low end machine I was also worried about if there is no batching at all without that Schedule integer argument , but I don't know how to check that

My code to create entities is created from watching tutorials, mostly from Samuli Natri's ECS youtube tutorial and blog. https://samulinatri.com/blog/unity-ecs-entity-component-system/ and also some other tutorials around

 using System.Collections;
 using System.Collections.Generic;
 using Unity.Entities;
 using Unity.Jobs;
 using Unity.Rendering;
 using UnityEngine;
 using UnityEngine.Rendering;
 using Unity.Transforms;
 using Unity.Mathematics;
 
 
 public class BootStrap : MonoBehaviour
 {
     
     public Mesh AsteroidMesh;
     public Material AsteroidMaterial;
     
 
     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
     private void Start()
     {
 
         var entityManager = World.Active.GetOrCreateManager<EntityManager>();
 
         var AsteroidPF = entityManager.CreateArchetype(
 
             typeof(Transform),
             typeof(Scale),
             typeof(Rotation),
             typeof(Position),
             typeof(MassComponent),
             typeof(Speed),
             typeof(MeshInstanceRenderer)
             );
 
 
 
 
         for (int i = 0; i < 10000; i++)
         {
             var AsteroidExample = entityManager.CreateEntity(AsteroidPF);
 
             entityManager.SetSharedComponentData(AsteroidExample, new MeshInstanceRenderer
             {
                 mesh = AsteroidMesh,
                 material = AsteroidMaterial
               
 
             });
 
 
             
             float x = UnityEngine.Random.Range(-3000f, 3000f);
             float y = UnityEngine.Random.Range(-3000f, 3000f);
             float z = UnityEngine.Random.Range(-3000f, 3000f);
             
 
             entityManager.SetComponentData(AsteroidExample, new Position
             {
                 Value = new float3(x,y,z)
             });
 
 
             entityManager.SetComponentData(AsteroidExample, new Rotation
             {
                 Value = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f)
             });
 
 
             entityManager.SetComponentData(AsteroidExample, new MassComponent
             {
                 Value = 1000f
             });
 
             entityManager.SetComponentData(AsteroidExample, new Scale
             {
                 Value = new float3(10f, 10f, 10f)
             });
 
              x = UnityEngine.Random.Range(-1f, 1f);
              y = UnityEngine.Random.Range(-1f, 1f);
             z = UnityEngine.Random.Range(-1f, 1f);
 
             entityManager.SetComponentData(AsteroidExample, new Speed
             {
                 Value = new float3(x, y, z)
             });
 
         }
         
        
     }
     
 }
 
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 mjussila · Jan 09, 2019 at 02:49 PM 0
Share

I think I found a solution. You can use IjobParallelFor inside Job system with ComponentDataArray inject

see https://connect.unity.com/p/part-4-unity-ecs-ecs-and-jobs

Third code example could be a good basis. That way it is possible to Schedule jobs with 1-64 batches.

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

97 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

Related Questions

Starting serproxy Process from Unity 0 Answers

External .jar and Windows Permissions? 0 Answers

When opening, Unity won't load until I terminate a powershell process 0 Answers

something still runs in background when I close my webView 0 Answers

Issue application.Quit Takes much time to close android application 2 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