What would the best way to be to display the remaining amount of enemies from a map ?
Announcement
Collapse
No announcement yet.
Display amount of enemies remaining
Collapse
X
-
I managed to complete it a different way . In the level blue prints i got all actors of class got my base enemy class promote that it a variable then got the length of that variable and used it to set the variable in the widget blueprints. It works well because every level will have different amount of enemies and it up dates on the fly
Comment
-
For a multiplayer approach without AI/bots (aka non-humanly controlled pawns):
With Teams:
- Create a custom PlayerState to hold a team name/team tag and add a method bool IsPawnAlive().
* This method will return true if the ControlledPawn is not destroyed or any criteria that works best for you. To access the PlayerController, cast the PlayerState->GetOwner().
- Create a Method inside GameState to return the number of enemies, and pass your team tag/name as parameter. ex.: int GetRemainingEnemies(FName YourTeam)
* The method should iterate through every PlayerState inside the PlayerArray , cast to your custom Player State and count each one that is different from YourTeam AND IsPawnAlive() is true, then return the counter.
Without Teams:
- Create a custom PlayerState and add a method bool IsPawnAlive().
* This method will return true if the ControlledPawn is not destroyed or any criteria that works best for you. To access the PlayerController, cast the PlayerState->GetOwner().
Create a Method inside GameState to return the number of enemies. ex.: int GetRemainingEnemies()
* This method will iterate through every every PlayerState inside the PlayerArray , cast to your custom Player State and count each one that IsPawnAlive() is true, then return the counter.
____
I would only suggest you to control the number of enemies in a variable if you are pretty sure you will synch it properly througout the game loop, otherwise not a good idea...
____
If you use AI/bots, you can use this local variable approach but make sure to update the counter when an enemy enters and dies. Or, you can use GetAllActorsOfClass and filter to your enemy classes/tags... but its way more expensive.
Comment
-
[QUOTE="
____
If you use AI/bots, you can use this local variable approach but make sure to update the counter when an enemy enters and dies. Or, you can use GetAllActorsOfClass and filter to your enemy classes/tags... but its way more expensive.[/QUOTE]
Can you elaborate on how it is more expensive
Comment
-
Originally posted by Deftones4 View Post
Can you elaborate on how it is more expensive
If you use an counter, then the cost is just 1 operation.
If you use GetAllActorsOfClass or GetAllActorsWithTag then:
1 - iterate through all actors in the game;
2 - save the matched references in an array;
3 - determine the size of the array.
So it's not only expensive in terms of cpu but also in terms of memory,"I have harnessed the shadows that stride from world to world to sow death and madness."
Comment
-
Originally posted by Deftones4 View PostIt's not all actors in the game just the level and if a level only contains say 20 enemies would that be an issue and is there a way to check the stats ?"I have harnessed the shadows that stride from world to world to sow death and madness."
Comment
Comment