Problems with setting up a winstate for a tower defense game

Hi all, im working on a tower defense game where the concept is you must destroy enemy knights before they approach your castle, using towers.

I have a winstate partially working where if the last of the enemies in the level enters the castle (where the actor gets destroyed) but you still have lifepoints, you win. Therefor i have the triggerbox thats located at the castle entrance, responsible for destroying the actors that get to the castle to check if actors of class are prssent. This works fine.

However, i have actor blueprints set up in the form of towers and also their respective projectile counterpart blueprint actors, but if the tower is responsibble for destroying the last enemy/actor the winstate does not work and i am struggling to set up a winstate accordingly for the tower.

In the screenshot you’ll see the level blueprint where i’ve set up the winstate for the castle, i’ve tried a similar check for actors in the tower blueprint and the projectile actor blueprint but it yeilds no results. Can someone please help?

bare in mind that i have a seuqnece of spawn actors set up in the level blueprint that spawn periodically in waves, so i do not want the winstate being activated inbetween waves when there may be no enemies.

Thanks!

Hello TheGoldstrum,

I have a possible idea, if it’ll work for you. First, have an int variable that tracks how many enemies are left (EnemiesLeft), along with an int variable that tracks what wave you’re on (WaveNum.) Whenever an enemy dies, or is destroyed, check both of those variables. If EnemiesLeft is less than or equal to 1 and WaveNum is equal to the last wave’s number (this could also be stored in an int of its own, just to avoid hard coding it), have the enemy trigger the win condition as it is destroyed. This should cover both scenarios where the enemy is destroyed by a tower or by walking into the castle.

thanks for this.

I’ve tried this out in the level blueprint by creating an int with value 28 which accouts for all of the enemies in the level. Then i deduct a value of one from 28 through a branch based on the condition “is actor being destroyed”. Then the tresulting value is shown with a print string. But this is not working, im not sure if the “is actor being destroyed” is not the way to go perhaps?

Is there a reason that this needs to be done in the Level Blueprint directly? If you were to do the subtraction as part of the enemy’s list of things it does when it destroys itself, you wouldn’t need to worry about the boolean possibly not working correctly.

Since referring to a variable in the Level Blueprint from outside of the Level Blueprint isn’t always a possibility, it may be best to put the int that stores the number of enemies remaining in the Player Controller or in a Player State.

On top of all that, be sure to try debugging your blueprint by watching it as you play to see if the functions for deducting the amount are being called at the right time, maybe the issue in the logic is somewhere that you’re not expecting.