Which is more expensive? (Performance-wise)

Ah, the good ol’ Memory vs Processing argument.

Let’s break things down.

Option 1 (N number of projectiles)
Pros:

  • Easy to Debug (no diving into raycast results).
  • More flexible as you could have various types of projectile behaviors/styles and the system would “just work”.

Cons:

  • Object overhead (Memory cost).
  • Iteration overhead (Draw calls, Update calls).

Option 2 (Uber projectile)
Pros:

  • Very little object overhead, iteration costs.

Cons:

  • More difficult to debug (multiple raycast results you need to check through).
  • Raycasts can be very expensive depending on their length.
  • Less flexible in terms of future changes.

You can mitigate some of the overhead from Option 1 by using an Object Pool so you only pay the overhead costs once and then just reuse the same objects over and over (@BrUnO XaVIeR has a Plugin that does just that: Object Pool Plugin in Code Plugins - UE Marketplace ). Option 2 might be fine, depending on your raycast lengths and if you simply can’t spare the memory.

Truth be told, you can guess at an approach all day long but you won’t know how things perform and where your bottlenecks are until the system are in place and you profile things. All things being equal, I would go with Option 1 with an Object pool type system.

1 Like