Jsou mé časovače efektivní?

I have many enemies in my app.

Each enemy has an effect, for example poison.

This effect lasts for a certain time, for example 60 seconds.

In each enemy blueprint I have a “Set timer by function name” event to calculate this ttl and apply the poison effect to the enemy.

My question is that is effective to have timer for each enemy? Because I can have for example 100 enemies in scene.

Or is there a better way? For example have some global timer that loops over all enemies in my scene?

Thank you for your opinios.

Hi there, yeah using a timer for each enemy can work, but you are right it’s not the most efficient approach, especially if you have a large number of enemies. Managing numerous timers can become resource-intensive. Instead, personally I would use a more efficient method of centralized or global timer that loops over all enemies and applies the poison effect as you mentioned. This approach reduces the overhead of maintaining multiple timers and can lead to better performance.

Centralized Timer Approach

Here’s how you can implement a centralized timer to manage the poison effect for all enemies:

  1. Create a Central Manager:
  • Create an Actor blueprint that will act as the poison effect manager, e.g., BP_PoisonEffectManager.
  1. Store References to Enemies:
  • In BP_PoisonEffectManager, store references to all enemies that need the poison effect applied. You can do this using an array.
  1. Implement a Central Timer:
  • Use a single timer in the manager to loop through the array of enemies and apply the poison effect.
  1. Apply Poison Effect:
  • In each enemy blueprint, implement the logic to handle the poison effect, such as reducing health over time.

Hope this helps.