- Home /
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: 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);
}
}
Okay return plantJob.Schedule(this, inputDeps);
seems to work...
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?
When using the ECS profiler are you able to see a list of all your entities? @mjussila
Yes, I do see them, I'm running a test with 10000 simple spheres.
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)
});
}
}
}
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
Follow this Question
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