How to set all actors (enemies) health back to max if player dies and respawns from checkpoint location?

Hi there, I’m trying to figure out a way to set all the enemies in the level’s health back to max is the player respanws- although I’m stumped…

I tried this but it didn’t work :skull: :

I’m sure it’ll probably be a simple fix- I’ve just got no clue how to do it-

The respawn is a custom event in the player so THAT event needs to reset the all the enemies still alive in the level’s health to max-

Any ideas/ suggestions would be greatly appreciated! :raising_hands:

There are a few options here.

You could destroy them all and respawn them. You can either get their current locations and spawn them there, or get their default locations through use of a variable and interface.

You can also just use an interface call to set their health. I wouldn’t recommend this one as it doesn’t reset their AI unless you tell it to, in which case that’s just more work.

And then you could reload the level entirely. It would reset everything in the level, but if you save it then that shouldn’t be a problem, as you’ll want players to be able to log off without resetting everything anyways.

1 Like

Hi Wilko,

My first thought is that you need to run the logic for each class in that ‘Out Actors’ array with a ForEach Node.

2 Likes

Thanks guys!! I’ll try these out tomorrow, appreciate it!:raising_hands:t3:

1 Like

Hi I’m so sorry for the delayed response- I just had minor surgery so I had to take a little break fr0m this project :skull:

I tried the for each loop node however it says error and ‘infinite loop’? Currently there’s only one enemy on the level so I’m not sure why it’s saying this :thinking: - I’ve probably done something wrong ahh :sob:

Because I can easily set the player’s health back to max after respawn since there will only be one of each player (it’s a two player game!) so I can just reset their health in their blueprints-

it might depend on your game but the above seem kinda like band aid solutions. ultimately a check point is a save system and likely you’ll need a save system eventually so may as well do it properly now.

another issue is if you’re looping over AllActorsOfClass you wont get potentially destroyed Actors.

1 Like

I have a checkpoint system atm but it just teleports the players back to a prior location rather than saving the level at that stage- although I think that does sound like a better solution honestly.

If this is just to reset the health to 100, in the SET node, just feed in 100 to the health.

The current logic translates into English as something like “Set the Health on this target actor to (Get the current health value of this actor)”

~

A step further - in the future if you want to have enemies with health values of higher than 100, you could have a ‘max HP’ variable in the enemy, and query that to set the correct amount on respawn.

Another idea - You could create a respawn function inside of the enemy with relevant reset code (reset health / position etc) - then you could just call the function on the enemy - same method as pictured above, iterating through an array (Get all actors returns an array) and executing a function on each item.

1 Like

Hi I’m so dumb- I already have a max health float that’s what I was supposed to plug in :skull:

But now it says infinite loop and crashes whenever the player respawns?

Disconnect the line going out from set health.

I just noticed your ‘SET’ node is looping back into the ‘For Each’ loop. That would be where your infinite loop is coming from. (As Dejan noted)

Now that you’re grabbing the ‘Health Max’ variable instead I think things should work as intended.