Handling multiple enemies as one actor

Hi all,

I’m attempting to recreate my own version of Space Invaders, I have BP_Enemy as the actor with multiple meshes and collision boxes so I’m not dragging them all out one by one and they move at the same time, also hoping this is more performant.

The issue is with my current method of working out which mesh/hitbox is no longer valid/destroyed and if ALL of them are invalid a widget should show up which isn’t triggering properly as I’m not sure what is the best solution for this is or even a working solution.

This is the logic in the BP_Enemy Event Graph / how I’m attempting to make sure all enemies are destroyed before showing the widget via ‘Game Win’ but it wants me to destroy them in order otherwise it doesn’t work.

This is the ‘Attacker Destroyed’ Macro it is using in the previous screenshot

1 Like

I’m pretty sure you’d be better off if you had them as single actors. Collision overlapped, destroy, that’s it. Otherwise, you spend most of your time figuring out which one is which.

You can use a blueprint to place them procedurally if you find doing it by hand a hassle :slight_smile:

Are they walking up and down, like the original game?

2 Likes

that does sound like a nicer way to do it, I’ve never touched the procedural side of things, I guess no better time than now, yes they are doing the walk down after hitting a wall then walking to other side, moving down then moving to other side again

1 Like

I guess you could have one actor ( unseen ) that is doing the moving. Each invader could have its own offset from that actor as a parameter.

You could do it with one actor, you would have to use something like

when the collision was hit ( sphere1 is a collision primitive ).

Consider Instanced Static Mesh components for this; it’s trivial to set up in minutes:

Hitting the invader:

It’s also exceptionally performant as we move the entire component and the whole thing is a single actor. Each ISM would represent one enemy type.

If you wanted to see if everything / enemy line is destroyed, query the component for instances remaining:

It’s a crude example, can be done better.

2 Likes

This is precisely the kind of logic I was looking for. I’ve made a mistake somewhere though? they zap back to the start instead of heading backwards



The TL for this would look close to:

So we get that oscillating, forth & back swing. You can, ofc, have many timelines. Load them dynamically, too. Or have a vector track instead of a float - 3x as much data.

Another way to handle this more gracefully, is to count the enemies as you add instances:

Subtract 1 when an enemy gets destroyed - when you arrive at 0, the stage is clear!

Hope it makes sense.


#cylonswerenotinvaders :innocent:

I’m not sure how to get that ++ node

Same as:

Okay this is the On Hit, which I imagine if you have a collision box set on the mesh itself it should always register a hit?

Note that the Hit should be detected in the Projectile BP. If you try it in the actor owning the instances or override instances’ events themselves, it may just crash - there is not enough data in the Hit - namely, the Hit Item is not generated - that’s afair.


Yes. And you’ll need to set up collision channels properly, too, ofc. Open the asset (the invader spaceship), remove collision first, and add a box or a more complex DOP:

And channels can be set up in a granular way (this is just an example, you’ll need your own). For now, you can set it to block all for the projectiles (which we do not how you handle yet) and the ship:

Hmm it still isn’t destroying for some reason

the bullet is just a projectile actor created when the player presses spacebar

  • post projectile actor component hierarchy and its collision setup
  • post collision setup of the object getting hit

Nothing in the projectile itself

enemy being hit

The projectile component setup needs fixing. Drag it to the root.

The Projectile Movement component cares only about what’s at the root.


Alternatively, add a simple collider as the root. You may need to adjust the collision settings of that collider, best have a look here if in doubt:

Hmm okay, but the projectile no longer goes anywhere it stays where it spawns

Because we now have actual collision… and the projectile probably collides with what fires it. That’s why collision settings offer granular controls. If you fire it from the Pawn, have the Pawn Ignore the projectile. The Pawn is shooting itself in the foot, most likely.


If in doubt, check what the projectile collided with.

Okay so character does this to shoot

character looks like this

It’s almost 100% what I mentioned above. The projectile collides with the Pawn that fires it. Have it Ignore the Pawn. Please check out the link I posted above. It might as simple as:

image

That’s be the setting of the projectile’s root collider.


Or spawn the projectile away from the firing Pawn.

I put everything on ignore projectile and ignore pawn and it still didn’t move, only adding an arrow and moving away from the character did it work sooo odd, the enemy still doesn’t get destroyed maybe thats collision related to

should this be overlap the player_shoot the projectile itself to destroy enemy then? or is there a better way