not sure if I’m using the right block or if ‘add unique’ is bugged with vectors or if I’m just stupid but its adding identical vectors to the array (no change in decimal points). any help would be appreciated!
It’s because they are vectors which are based on floats. And the floats aren’t perfectly identical. Remember this behavior when working with locations as this problem will prop up in other ways.
The Add Unique function adds a value to an array only if that value is not already present. It’s important to note that the variables you add to the array should not have duplicate names.
Why doesn’t Get Actor Location work with Add Unique?
When you try to add a vector obtained from Get Actor Location to an array, it is created as a new element with a unique index. Because of this, Add Unique does not recognize it as an existing value and does not prevent duplicates.
How to solve this issue?
Option 1: Checking with For Each Loop
- Iterate through the SpawnLocationArray using a For Each Loop.
- Check if the value already exists in the array using the “!=” operator.
- If the value exists, do not add it; if it doesn’t, add it.
Option 2: Using Contains
- Use Contains to check if the vector from Get Actor Location is already in the SpawnLocationArray.
- If Contains returns True, the value already exists, so you don’t need to add it.
- If False, the value is not in the array, so you can add it.
Both options work; the choice depends on the situation.
I added Not Boolean, that’s why I used True.