I have tiles that toggle on and off when someone steps on them. The object of the game is to activate all the tiles. I just need some way to check if all of my tiles are active. I already have a boolean set up for this. what would be the most efficient way to go about this?
asked Jun 03 '17 at 04:01 PM in Blueprint Scripting
You can use the Get All of Actors of class node, and then select your tile blueprint. This will give you an array with all your tiles in it. You can loop through these and make sure they are all activated by checking your boolean.
Hope this helps, be sure to mark answer as correct if I helped, leave a comment if you need more help :)
answered Jun 03 '17 at 04:09 PM
The best way to approach this is, in my opinion, to have a parent blueprint that acts as a manager. Let us call it the MapBlueprint. Each MapBlueprint spawns NxN tiles where each tile is either off. Then, this manager class stores a variable that holds the number of total tiles as well as the number of activated tiles. Each time a tile switches it calls a function of the manager class that increments or decrements the NumActiveTiles variable, followed by a call to a function that checks if the game is finished by comparing the two variables. If NumActiveTiles == NumTotalTiles, then the game is done.
This is the most effective way to solve this problem from a performance point of view. Using the node GetAllActorsOfClass is much slower since it requires the code to loop through all objects in your game and then loop through each tile every time you change a tiles state. If you do it on tick, you would have to do it every single frame.
answered Jun 03 '17 at 05:50 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here