How to clear duplicate array values?

Hey all I have a simple spawn function for a dungeon that will run traces along the ground and tell it to spawn specific tiles depending on what is hit with the trace.

However the trace circle has to be big enough to hit up to 3 tiles away. The problem:

The circles will hit the same tile multiple times, adding it to the array over and over causing the tiles to be spawned inside each other and causing heavy fps drops when approached.

As the tiles are hit and the conditions are met their location is added to an array and then they are destroyed or they are just destroyed or nothing.

But then I for each loop through the array and spawn a tile on each location. And since there are multiple copies of the same location they will spawn many times over.

The array is completely randomly generated every time and quite large; if it were to work correctly about 250-1000 HISMs. So I have no idea how to make it auto check against itself. I can’t manually tell it to avoid “x” duplicate(as it may not exist the next time it is ran).

Code

Any help appreciated.

Hmm doesn’t seem to effect the final count.

Okay I ended up having the trace location be based off the last tiles location, coupled with the add unique seems to fix it. Thanks.

Try the “AddUnique” instead of “Add” on the array. Tell me if this solves your problem.

2 Likes

Oh! Hmm, you will also have to remove the used location from the array after adding the new instance. Does this work?

EDIT: sneaky ninja-edit on your part. glad it’s fixed :slight_smile: