Having an odd issue where I have two systems setting the LocalTransform scale. However, the first system to execute always seems to overwrite the last one.
What I'm trying to do:
- Clear all mouse-hover circles
- Show hovering circle for the one entity (hover circle) closest to the mouse cursor
https://paste.mod.gg/etwlvnynbyuw // Latest version
(Screenshots also added for highlighting)
I've divided this into two systems (Screenshots 1 & 2). One that quickly executes on all entities with a job. The other system uses an EntityQuery and a loop to determine which entity is closest and should show the circle.
Basically, one system can freely parallel-operate all entities, while the other has to compare them all and will only change one. It seems to make sense to keep them separate.
The latter system calls EntityManager.SetComponentData to overwrite the changes supposedly done by the earlier job for a single one of those entities. I've also attempted using an ECB here to perform this change at the EndSimulationEntityCommandBufferSystem.
While writing this I've found my best guess to be that the automatic Job Dependency doesn't take EM and ECB component calls into account, and that the scheduled jobs are executed later than the second system.
https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/scheduling-jobs-dependencies.html
(To be fair, the second system is executed right after the first one, but again ECB usage didn't seem to fix it)
The systems' OnUpdate calls are happening in the correct order. This I've confirmed with logs, and the entity profiler (Screenshot 3). I've also added UpdateBefore and UpdateAfter attributes to ensure this.
So I'm wondering what would be a good way to approach this:
- Make the second system use a job and count on the automatic job dependencies.
- Combine the two systems and complete the "clearing" jobs before setting the single "hover" circle.
- Combine the two systems and make both operations use jobs. Set the first job as a dependency of the first.
- Find a way to store the first system's job handle. On the second system, get the handle and ask the job to complete. If so, what's a good way of doing this?
- Avoid changing the same property in multiple systems.
(I should probably space out these systems in time so there's more time for the first jobs to finish before I have to force complete them)
Am I missing something obvious? 😅 If not, any inputs on which approach is better and maybe some tips on how to achieve it? I'll appreciate any insights into the ECS "best practices" while I'm learning and testing things.
A tool for sharing your source code with the world!
I attempted option 4 by storing the job handle in a static field so I could reach it from the second job. I'm calling complete while stile in the first system's OnUpdate. Then in the second system, double-checking that it's completed, which it is. But the circles are still invisible (scale = 0).