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);
}
}
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
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)
});
}
}
}