Download

selecting a number of objects in the level and deleting only some of them

Hi. I’m still fairly new at blueprints and appreciate any help or pointers.

I’m trying to create an automated city builder like simcity and want to script something like, automatically after 3 small houses are built, destroy those houses and build a bigger house. So if the level starts out with a small house already in it, how do I incorporate that into the number of small houses existing in the level? Then, lets say I want to have at minimum 5 houses in the level, and destroy three at random so I can build a bigger one.

I’ve just been pondering at it so far, haven’t created any blueprints for them yet. Thank you!

update:
I’ve got the creation blueprints and variable of number of houses at start done, just haven’t figured out how to destroy three of them at random.

This is an array created at start, I haven’t figured out what to do with it. I use a int variable which you can see in the 2nd pic to keep count of the number of houses at present.

And this is what I’ve got so far to destroy the houses. So how do I implement the array and choose three of them at random to destroy? Thank you!

You can destroy three random elements from the array using this:

It will store a random index of the array each time, destroy the actor at that index and then remove that array element altogether so that you won’t have to worry about it during the following iterations.

Hey thanks Stormrage. It works but I’m getting errors about it unable to find the reference because it destroyed itself so the references no longer exist. I’ve done it exactly your way, and I’ve been trying several other different ways, but haven’t gotten rid of the errors yet. I’ll keep trying!

I’m guessing that it’s because the Event Dispatcher is destroying the houses before you start the for loop. Try disconnecting the Destroy Actor node in calltodestroy event, and instead call the function to randomly destroy three houses using the array from your first screenshot.

This will work:

Thanks both of you for the feedback. Both ideas helped me a lot. I ended up storing the variables in the character who doesn’t get destroyed, and referenced them in the eventgraph of the house actor to be destroyed, and no more runtime errors. Now to deal with a new issue that is not supposed to spawn the house at a totally weird random location.