i want to run some code can auto stop after several seconds, but i dont want to realize it by a manual timer.
First question would be, why your jobs run for that long.
Jobs run usually on a thread and once running, can be controlled from the inside of the job. Hence you need some iterupt logic.
ECS kinda backs away from these weird “magic callback” code constructs like InvokeRepeating because they’re not very performant. In the long run, they also make the control flow somewhat complicated and unpredictable. Questions like “which piece of code executes first?” become hard to answer.
I do think we could use an ECS-native, low-effort way to achieve the same thing, though. (Haven’t played around with this, so I’m not sure what the code would look like, but I do imagine there’s at least some boilerplate.)
Manual timers are extremely simple, performant and execute deterministically. You should use a manual timer and store the timer data in a component.