I’m new to Unreal Engine and I have been making a simple ball and paddle game as a practice. So the idea is when the a block (destructible mesh) gets hit by the ball, it fractures and falls down and glows like a star and then despawns after it’s out of the screen view(which takes about 10 seconds). Now I want the ball to stop after all the blocks (destructible meshes) are fractured (not despawned, fractured) so that there won’t be a chance that the player will lose after he destroyed all the blocks. Now as you can see in the screenshot, I made it so that if a block fractures and there’s one block left that means it was the last one so the ball stops, but that’s not gonna work when the last two blocks fracture at a short period of time (less then 10 seconds) because the second last block needs to be despawned for this to work. So I’m wondering if I can count how many destructible meshes haven’t been destroyed yet in the level, or maybe a way to count the fracture as a “kill”… I don’t know, just a way around this maybe?
Is there a way to count how many destructible meshes haven't been destroyed yet in the level?
differents options here,
i think a good start would be to store all your destrucible meshes in an arry, and remove them once they are destructed, and check this arry length to see when the last one collapse.
the easiest way to track it should be to do a parent class for all your bricks.
As mentioned above, many ways to count stuff, here’s one:
Count up as you add, count down when you fracture:
So I’m a little confused. The script that you have here is perfect for me but I don’t get the bit “count up as you add”, specifically with the node “add destructible component” (again I’m a beginner). I get the rest of the script but I get confused with this node, first, where should I get the execution pin to it from? And second, what does it do?
it adds a component to your blueprint, wich is a destrucible mesh.
specifically with the node “add
Tell us how you add the destructible meshes to the game. Are they actors with a destructible mesh component and you’ve dragged them into the scene? Or you Spawn Actors From Class dynamically.
You probably do not want to count inside the actor that will be destroyed anyway. Ideally, you’d have something else keep track of the remaining blocks. The actor serving as the Paddle might be a decent choice to do it (unless you destroy Paddles as you go). The Game Mode blueprint is a fine choice.
Essentially, taking into account that each destructible is a separate Actor, you could run this when the game begins (just don’t place this script in the block itself):
In the script I posted earlier, the destructible meshes are just components, they are added dynamically and all belong to the pyramid actor. Rather than laboriously adding destructible blocks one-by-one to the scene, I run a loop and X components are added in a pattern. So I can do this quickly:
If you’re planning on having multiple levels with different patterns of blocks, it might be good idea to script some kind of spawning method. In case where the destructible is rather simple and its only purpose is to be destroyed, there may be no need to wrap it in a full actor. It’s more performant this way.
I see what I was not getting… Yes I have an actor blueprint with a destructible component and yes I drag them one by one
Then you can use the script I suggested above.
I tried this second script and now I got it working… but first I had a problem with debries max lifetime enabled and the number was going crazy low(like -100 or even less)…it was counting each chunk disappearence, so I disables it. And then I had to disable collision after the fracture because sometimes it was hitting it twice which means counting the same block twice…but now it’s working perfectly.
Thank you guys so much.