Semi-random object spawn in defined target points

Hey everyone, I’m trying to figure out a way to spawn an object at 3 of the 5 defined locations each time the game starts. Below is my pseudo code but I couldn’t figure out how to implement this into a blueprint or cpp in Unreal.

Pseudocode:

// 5 target points
// spawncount = 0

// target 1: 60% spawn chance
// change spawncount according to result

// target 2: if spawn count 0, 75% spawn
// target 2: if spawn count 1, 50% spawn

// target 3: if spawn count 0, 100% spawn
// target 3: if spawn count 1, 66.6% spawn
// target 3: if spawn count 2, 33.3% spawn

// target 4: if spawn count 1, 100% spawn
// target 4: if spawn count 2, 50% spawn
// target 4: if spawn count 3, 0% spawn

// target 5: if spawn count 2, 100% spawn
// target 5: if spawn count 3, 0% spawn

Just put the spawn points in array, shuffle it, and take the first 3 :slight_smile:

Thank you so much for your reply, I’ve been working on it but I’ve two issues right now. First of all, I couldn’t understand what to bind under “<”, and (possibly because of that) I can’t seem to make items spawn on defined locations. Would you mind advising further?

I’m sorry if that question sounds silly but I’m quite new to Unreal :blush:

You’ve got it right. N is the number you want to use.

Can you spawn any with this stuff? Like, spawn 1 on begin play?

Ok I made it work! I added a new variable as an integer and defined the spawn count. Thank you sooooo much!!! :heart_hands:

1 Like