Many Ticks vs. One Tick

I have a ABeehive class that constantly spawns ABees. And I wonder would it be better if I had just ABeehive with an active Tick function that would run ABees game logic from it. Or I shouldn’t bother with it and just use every ABee individual tick for it?
I am not knowledgeable enough to assess how bad active Ticks for performance, but as far I can guess even if I have a really big interval between Ticks it constantly reads clock and in a long run it shouldn’t be good with a lot of them.

Hi McBlyad,

Spawning something on tick?! That’s madness!!!

1 tick = 1 frame, so the intervals would always be really small.

I think timers might be what you need.

It’s not a bad idea. Consider doing the updates via an Event Dispatcher rather than calling ForEachLoop on AllBeesArray.

@Astrotronic and @Everynone :

Would it be unreasonable to already have the actors in the level, just hidden, and using a loop function, un-hide them, instead of actually spawning?

I have a ABeehive class that constantly spawns ABees.

I don’t think this is about BPS (Bees Per Second).

I believe OP’s hive keeps spawning some bees every now & then, maybe more often, maybe more consistently but not every frame. They want to run their logic on Tick, though. At least that’s what I got.

3 Likes

It sounds potentially expensive.

I thought even pools might be a better option.

Still demystifying optimization.

I don’t think the ask here is about spawning at all. Pooling, while desirable, may not be applicable/relevant here, not for this question. It’s not about bee death/life cycle.

OP is asking: What is more performant:

  • 1 hive actor ticks 100 bees
    or
  • 100 bees tick on their own
1 Like

Got it.

Still the question remains, would the above technique (because I plan to do something similar) be viable?

Pooling? I’d say yes, but you need enough stuff to justify the upfront cost of setting it up and the added complexity of managing it. If you’re shooting 1000 of bullets, probably a must. If you’re herding 10 bees, probably not.

Spawning is costly, and so is throwing stuff for the Garbage Collect to discard (less so, ofc).

2 Likes