How do I placea specific actor from an array only once into my scene?

Hi,

I have 6 different actors assigned to an array which should be placed randomly at 6 specific locations in my map, since each time the game starts the same actor shouldn’t be found at the same location as before. With a random integer > get node they are selected from the array and then spawned.

The problem is however that the same actor can appear multiple times in the map, since the random integer node doesn’t know if an element has been previously called or not. It just spits out random numbers ranging from 0-5.

What I am looking for is a way to determine if an actor has already been spawned and if yes ignored and not spawned a second time. I hope I was able to explain the problem. Does anyone have any idea how to fix this?

You could make an array of integers that fills up with with whatever random integer you get with the “random int > get node”. Then check against the array to see if the integer is already there. Then you could re run the random get or do a ++ or – to get the next or previous number until you find one that is unused.

Thx for the help, however since I am not to experienced with UE4 could you please elaborate on what you mean by “check against the array”

Give this a try.

You can create a second array, that is copy of first, spawn actors from there and then immediately remove from array. This way you will be sure that each pick is unique. I wouldn’t advise checking initial array to see to see if actor is already spawned or not, because it will lead to multiple checks (you choose an actor, check - it’s already spawned, you ignore it and choose another, check - it is also already spawned, you ignore it and choose another, check - it is also already spawned, you ignore it and choose another, check - it is also already spawned, you ignore it and continue trying)
[SPOILER]

[/SPOILER]

Was looking at other ways to get the same effect and came up with this. Can be done with or without the delay node or integer variable. If you do use it, know that it runs per tick so if you have 30+ actors it will take 30+ ticks to complete.

Why not just:

This was a tough one!! But thanx to all of you guys’s help I could sort it out. Here’s the way I got it to work so that I can randomly place 6 actors to 6 specific locations.