Advanced "Random Actor Spawning" Blueprint


i’m having a little problem with my item spawning system. Here’s a screenshot:

At the current state the system spawns an actor from the list at the given location. But it’s not random enough for my game. If i create 15 spawns (with 10 actors in the ActorList) the game will place the actors in the 10 first spawn points.

This is what i want:
I want to spawn exactly 10 items (of a longer actor list) in my level. I create ~30 possible spawns around my level. Each time i start the game the system should choose 10 items of the list randomly and spawn them in one of the given locations. The same item should never spawn twice. The 20 unused possible spawns stay empty.

Kind Regards!

Is because you are using the same location for every actor… do I am wrong?

Oh i forgot to mention this and maybe you got confused. The blueprint script you’re seeing is in a Actor Blueprint. I place this Actor blueprint at several locations on the map and spawn the items at the given location.

It looks fine.

Where are you randomizing the thing? Looks like in another bp?

If I understand you correctly . What I would do for problem one . To stop the same item spawning twice is when you spawn that item add it to another array eg spawned items array and then before you spawn an item do a check by iterating through to see if that item already exists within the spawned actor array if it does then skip it and generate a new random array index if it doesn’t already exist then you know it will be a unique spawn.

Other options are removing it from the array once spawned but if you need to repeat the logic you would have to rebuild and sort the arrays . Another option is for example having a boolean eg isItemSpawned and setting it to true after spawning and checking it before spawning

Also for the random positioning of objects rather than manually placing 30 actor bp in the world where you want things to spawn you again could have an array of all the possible spawn transforms saved and when you spawn again just pick a transform out of the array

Also check out this tutorial by epic

It teaches about creating a spawning volume which you can place in the level and scale as required so you can spawn things either in concentrated areas or all over the map which I think might be more suited for you unless you are doing a overly customised system

Also check out this thread it is an awesome bit of information. In this case he is spawning enemies but it doesn’t matter it can be used for items or anything you want

Hope this helps any questions or need further help feel free to pm me here or skype me on enigmalabs

“Other options are removing it from the array once spawned but if you need to repeat the logic you would have to rebuild and sort the arrays . Another option is for example having a boolean eg isItemSpawned and setting it to true after spawning and checking it before spawning”

A way to do this would be to set up the isItemSpawned variable as an array and hold the same amount of content as the ActorList. Check the isItemSpawned index that corresponds with the Random Integer, if it’s not set, set it and continue on with the Spawn. If it is set, loop back into the Random Integer (Cast To…).

I should mention that the isItemSpawned variable is housed in the same location as the ActorList variable.

So i had some progress and did put my blueprint system in my gamemode. Im now able to spawn a given amount of items from a list at random locations. But sadly the system doesn’t work as intended. The same item spawns more then once and sometimes even on the same location. I’ve read your posts and saw a suggestion that i should implement boolean-arrays to save wether i already have spawned the item ( + used the transform) or not. Well, i did that and the system even recognizes duplicates but it seems to spawn the wrong actor at the wrong location. Help?
Here are all parts of my code:

This is because you are forgetting the array indexes won’t match you are storing the array of transforms for each item but when you spawn the item it doesn’t mean it will use the right transform that matches the item because it all depends on the order and indexes they are in the array.
And when it finds a duplicate and skips an item or transform it again will mess the order up

And you are really making things complicated . I cant get on my computer at the moment and it’s a bit hard to explain without showing you blueprints but as soon as I can I will post up the answer .

Unless someone else does or you figure it out in the mean time .

An easier way would probably be to place the isItemSpawned variable in the Parent class of the items you are spawning around the level. If they do not have a Parent class, make them one. Place the variable in there and make it Editable and Exposed on Spawn.

Before spawning something, check if the actor’s blueprint has the isItemSpawned variable set to True. If not, spawn that blueprint actor and set its isItemSpawned variable to true.

This is assuming that all of those different things you are spawning are all different blueprints of one common blueprint amongst them (Children of a Parent blueprint).