Did a quick demo to test it out. this is what I ended up with: Chain closest within radius - YouTube
It’s a bit longer than I thought it would be so rather than sharing blueprints, though of just summing up the steps to build it. I’m doing this in an actor component + spawning another actor for the timed “jumps”. These are the steps:
- You’ll need several arrays for this. the first one is ActorsToIgnore → this will hold the actors that have already chosen as closest. Your trace hit should add the first to this array.
- I used Sphere Overlap Actors node with the ignore array connected. You can specify the specific class you want this node to return.
- check if the overlap returned 0 to cancel. If not make an array ( OverlapedActors ) and loop through it. On each index get the distance of the last actor in the ignore array vs the overlap array. Then add that distance to a new float array.
- When loop is complete, get index of smallest distance and use that index to add a reference from the overlaped array to the ignore array. This way we are building the ignore array so that for next loop, it skips calculating distance and we are also building it in order as found from first actor hit.
- Now you need to check the count: I made 2 ints; one for current and one for total jumps. Add one to the current, then check with a branch: If current != total → clear both float array and overlaped actors array and call the loop again.
I found I needed 2 checks to avoid access none:
- First one is right at bullet#3 when we check the overlaped actors: if array length == 0 → No more targets so reset current count, float array and overlaped actors and move on to jump with timer.
- Second is when current count == total → Reset same as above and move on to jump with timer.
For this final part, I spawned a new actor that only recieves the ignore actors array and I reset all remaining variables for next time player interacts with a valid actors.
Thought spawning a new actor was the best solution because it allows to have multiple chains running at the same time, each with their own timer.
- Character traces
- Hits valid target and passes to component
- Component finds closest of first target, adds to array, then finds closes to second target ignoring what’s in the array, etc…
- Spawn actor with copy of closest actors in order and do stuff.
Hope it helps. Feel free to ask if you need clarification on something specific.
Just FYI: did not use a single delay node for this. Only a Timer by Event in the spawned actor.