Deactivate / Destroy Actor When Not On Screen

Hello all!

So, my goal is to have an actor deactivate or be destroyed when not visible after being spawned.

If any of you has ever played a SHMUP (i.e. UN Squadron or Cuphead), you’ll know what I mean.

During an on-rail shooter, once the enemy passes out of the camera it needs to stop targeting the player from off-screen.

Any ideas of the best practice for this?

For reference:

I’m not really sure what the video is supposed to show, but you can simply add some colliders a little over the edges that kill anything it touches.

The gameplay does look fast, so you might want to look into a pooling system instead of destroying them outright- pooling systems basically reduce the number of times actors are created and destroyed.

1 Like

Thanks for the reply.

It’s on-rail, so everything is pre-scripted. (Will be choreographed in sequencer).
The video is to show the style of gameplay.

An out of camera collider sounds interesting!

1 Like

Pool your re-usable actors

Collision box on the left side, spaced far enough left that left entering actors do not collide. Shape it to vertical rectangle. Top to bottom of screen space, but only about 100cm wide.

On End Overlap → Actor → return to pool.

Spawning and destroying are performance hits. Especially at high frequencies.

2 Likes

@rokenrock ,

Hey, you two, so the only issue I have is how the pooling will work with the sequencer.
Everything (except projectiles) is choreographed; not procedural or random.

I could potentially pool projectiles… but I feel like pooling enemies can get messy.

I’m brainstorming… but it seems that trying to pool could cause bugs with the sequence.

If it’s a sequence, you can just implement the pooling system yourself. Instead of creating a new actor, you can move the out of frame ones and use them.

1 Like

Thank you so much for the advice!

So useful to get other perspectives. I better understand how to effectively use the pooling technique with the sequencer.

For any future programmers:

  1. Set up the entire choreographed on-rail sequence in the sequencer, taking care to limit the amount of actors you use. (A good practice would be to sketch the level by hand BEFORE coding anything)

  2. Anytime an actor/enemy is defeated, using an Overlap function (Begin or End, depending on your needs; for me, it’s Begin), set visibility to HIDDEN and disable COLLISIONS and any attack logic you coded.

  3. If an enemy is not defeated, and falls out of view of the passing camera, set a geometric collision (usually box) that spans the height and depth of the level, just out of camera view that moves with the camera. This geometry will act like the player’s projectile and “KILL” the actor.

  4. MOVE deactivated, hidden enemies further along the level to be used again in the sequencer, reactivating logic, visibility, and collisions.