I tried renderSystem.Update(); right after I created the system and it did call OnUpdate, but only once since it was done in the Start() method. Isn’t there a way to make a generic system run automatically just like a normal system? If not, do I have to call the renderSystem.Update() somewhere myself every frame? If so, where? In the Update() of a Monobehavior or a system? An example would be greatly appreciated since I couldn’t find any info on this. I’ve heard some vague words about System Groups but that sounds intimidating since I never actually saw an example on how it’s done.
I tried doing renderSystem.Update() inside a Monobehavior Update and it seemed to work, but I’m just not sure if I’m getting the best performance that way. Is there a better way or is that it?
Probably because it does nothing, as far I know if JobComponentSystem.OnUpdate called only if it has entities to work with and this check is done with manually created EntityQuery in OnCreate or automatically created EntityQuery based on scheduled job.
Try to create EntityQuery in OnCreate method or schedule the actual job in OnUpdate.
It’s not entirely true. If you haven’t any EQ it will runs like with [AlwaysUpdateSystem] attribute - always.
@Radu392 your problem is your system not in player loop (cause it’s generic), after creation you should put it in to some of root component groups (Initialization, Simulation, Presentation).
using Unity.Jobs;
using Unity.Entities;
using UnityEngine;
public class TestJob : MonoBehaviour
{
void Start()
{
var simulationGroup = World.Active.GetOrCreateSystem<SimulationSystemGroup>();
var s1 = World.Active.GetOrCreateSystem<GenericSystem<Data1>>();
var s2 = World.Active.GetOrCreateSystem<GenericSystem<Data2>>();
var s3 = World.Active.GetOrCreateSystem<GenericSystem<Data3>>();
simulationGroup.AddSystemToUpdateList(s1);
simulationGroup.AddSystemToUpdateList(s2);
simulationGroup.AddSystemToUpdateList(s3);
simulationGroup.SortSystemUpdateList();
}
}
public struct Data1: IComponentData{}
public struct Data2: IComponentData{}
public struct Data3: IComponentData{}
public class GenericSystem<T> : JobComponentSystem where T : struct, IComponentData
{
protected override void OnCreate() {
Debug.Log("Created: " + typeof(T).Name);
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Debug.Log("Updated: " + typeof(T).Name);
return inputDeps;
}
}