How to implement behavior like StartCoroutine by Entitas?
See original GitHub issueHi there, I’m migrating my game to using Entitas, what I have now is HitComponent and my code rule is, when entity.isHit = true I need start a coroutine, waiting for 1 second and this coroutine’s going to set entity.isHit = false.
Since my system is not extending MonoBehavior, I can’t access StartCoroutine function, how can I do this by Entitas way?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to implement behavior like StartCoroutine by Entitas?
Give HitComponent a field (float cooldownTime) then do entity.AddHit(cooldownTime). Then have a HitCooldownSystem : IExecuteSystem that iterates ...
Read more >ScriptableObjects and Coroutines
The basic idea is that a ScriptableObject which wants to run a Coroutine spawns a GameObject in the Scene which will hold the...
Read more >Manual: Coroutines
A coroutine allows you to spread tasks across several frames. In Unity, a coroutine is a method that can pause execution and return...
Read more >Coroutine in non-monobehaviour script for a fsm. : r/Unity3D
The issue is I cannot use coroutines in any of my classes as they all inherit from the base state FSM class. Is...
Read more >Coroutines in Unity (how and when to use them)
In this step by step guide, learn how pause functions and script sequences of events the easy way. With Coroutines in Unity.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You could try this:
Give HitComponent a field (float cooldownTime) then do entity.AddHit(cooldownTime). Then have a HitCooldownSystem : IExecuteSystem that iterates through the group of entities with hit components, subtracting the delta time from the timer value. When this hits 0, remove the hit component.
@lai32290 @FNGgames summarized pretty good (as always 😉) first answer is a very common way to deal with timers and cooldowns. I’m just commenting to emphasize not to do the 2nd solution. Technically it works, but you would basically hide logic in a component, which you should avoid.