Respawn Enemies

Hi everyone!
I would like to respawn enemies by keeping track of how many there are currently in the map, and if 10 or less remain then they respawn.
Currently my actor is created this way and logically it seems correct to me, what do you think I’m doing wrong?
Currently the respawn happens just a couple of times then they never reappear.

Plus every time an enemy dies I put that they have to remove 1 from the total amount.

Perhaps there’s no need to get Tick involved:

You have delegates, use them.

  • increase the count when enemies spawn
  • decrease it when they get destroyed
  • if threshold has been reached => respawn

Also, you can expose variables on the base class:

image

They will appear on the spawn node directly. There’s no need for any of those wires or casting. This will also make their new values immediately available in the Construction Script which the children can still override as needed.

Consider it.

1 Like

Thank you!!!
It works perfectly, unfortunately I hadn’t used delegates until today so I had to do a little research about it.

At the beginning it gave me “none access trying to” because I’m spawning AI actors so the output node was on pawns, so I had to reuse a cast to enemy base to convert from Pawn to Actor (I guess?).
If there is a more functional alternative to the cast or simply if you think I haven’t understood the real problem (which is very likely) please feel free to suggest.

1 Like

You can just remove those 2 nodes (unless the Cast failing is important here for other reasons):

Setting data with exposed variables becomes easier and does not require a cast:

The base actor class (which every actor in the engine inherits from) already dispatches its destruction event:

You can also use the keyword assign - it will automagically generate a connected event node with a correct data signature. Saves you a click!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.