Download

Random Object Spawner ++

Hey guys,

I’m somewhat new to the UE4 scene and I’m trying to get something done.

Basically, I’d like to spawn objects, but have their chances of spawning randomized and also limit their spawns to a fixed number per playthrough.

Example: There are 20 boxes on the floor each having the possibility of spawning an object inside them, but only 3 out of the 20 boxes can spawn those objects and each playthrough is different.

My question is… where should I start? Does anybody know any tutorial(s) that could guide me a bit? Any examples? Thoughts? Dance moves they’d like to share?

Thanks in advance! :slight_smile:

You can start here:

This will give you 20 boxes that may (25%) have loot, but no more than 3. If the boxes are already in the level, add them to an array and ForEachLoop through *that *array instead, only setting flags rather than spawning new boxes.

Wow that’s great! Thank you so much @Everynone! :slight_smile:

As soon as I posted this question, I thought of something else to accompany it but it might be a bit more work than my first question though… if you feel like you’re up for the challenge, feel free to help me out again! :slight_smile:

I’d like to have it as a “spawning volume” that I can place inside the box making it a parent spawner that way I can easily place the boxes around the level.

My follow-up question is:

  • The loot would be something like 3 apples, 3 bananas and 1 key. How would the parent volume know that out of the 20 boxes (same parent) I’ve placed in the level, only 1 out of the remaining 13 boxes would hold the key the rest would hold 3 apples, 3 bananas and the leftover boxes would be empty? All randomized per playthrough…

If I’m wording it wrong let me know… trying to be as precise as possible. :slight_smile:

if it’s a lot of work, you can skip this question… lol

thanks ​again! :slight_smile:

There’d be usually no need to spawn loot until the player opens the box. Once the player does access the contents, the box checks its own *hasLoot *flag - if it’s true, spawn a healthy choice of fruit at the box’s location. If you want to pre-spawn the loot (you may have lots of reasons to do so), you can use the box’s Construction Script instead, showing the hidden items once the box is accessed.

  • I’m not really sure what you refer to as parent volume - is it the volume that the boxes are located/spawned in/by?
  • Why does it need to know which box has what? - there might be a reason, just asking
  • and or *or? *Each box has *either *bananas, apples or a key, right?
  • all boxes are held in an array, hold the boxes with loot in a separate array; a single box can be in numerous arrays
  • or give the boxes tags indicating what’s inside
  • or loop through the boxes array and check if they *haveLoot *and what it is

Consider sharing a bit more about how you envisioned the gameplay mechanic, it might be easier to suggest something more tangible.