Stop Array Duplicating?

Hello, sorry if this posts twice, not sure if previous worked or not ://

I currently have 3 objects being randomly spawned into my game at different positions. These positions are decided by 5 target points around my map. (3 objects randomly spawn to these targets). Unfortunately sometimes an object spawns twice on these targets, meaning that the object in the array was chosen twice - or the random integer.

I need some way of making it so that the 3 objects spawn accross different targets and dont get selected twice.
When the round ends all the 3 spawned items are destroyed and 3 more at random get spawned in, just thought i would mention that in case that changes the blueprint in any way.
Im a real beginner at ue4, so a relatively easy to follow answer would be excellent.

Thanks in advance!!

Tick is for things that happen every frame, this doesn’t really fit the bill. Try it like this:

I just press a key to re-spawn:

It works:

299900-spawning.gif

One array is of type ActorClassReference, the other is an array of the spawn points.

Neither, you can’t remove from an array while you’re using it. You’ll get all sort of weirdness if you try that. Also you’ve got a massive struggle if you do it on tick, because it’s trying to run every frame and you have to somehow make sure it doesn’t, it’s a mess…

EDIT, it is technically possible to put it on tick, but it still wouldn’t look like your code I’m afraid. You’d need to have at least a boolean saying when and when not to spawn, and you’d have to set that bool using a custom event. So, it’s not really on tick anymore because you’re putting other functionality elsewhere.

Yeah, you could put it on tick if you had the same number of things in both arrays and went backwards through the arrays ( then you can remove ), and checked the index was >= 0. But even then, you will be checking the index every frame forever from then on in… :slight_smile: - don’t do it, nightmare :>

Wow what a great response thank you so much! And yes the tick like you said is a terrible way as you said. Using my original example, how would you plug into it however? Just for my sanity as I spent hours trying to do it. Do you plug in a remove index in the random integer? Or is it a remove object node i would’ve had to plug in?

okay thank you for clearing that up, much appreciated

Yes dont worry ill stray away from here dont worry! Just one question, the arrays you made in your example. I presume I just create 3 array variables of type actor? Then the target array has my spawn targets in… the my actors array has the actors i want to be spawned… and the spawned actors array is left empty? Ill link a screenshot of what i mean.

The other two arrays are exactly the same, the only difference being under ‘defaul value’ at the bottom i have it filled with 5 references (either to my targets or actors).
Sorry once again, im very new to all this :((

There’s only two kinds of array. One is of type ActorReference, that’s for the spawn points. The other is of type ActorClassReference, that’s why it’s purple. That way you get to say what kind of things you want to spawn, you just don’t have any of them yet :slight_smile:

Uh, sorry, yes and the third array is ActorReference also ( the one where you put the list of spawned things ).