Fill Variable Based on Proximity

Hello, I have a basic portal blueprint that I’ve built and it’s mostly complete, there’s just one facet of it that needs to be finished. The way my gameplay is set-up, the portals are divided into Portal A and Portal B. The general idea is that Portal A teleports the connected characters, pawns, and actors to Portal B and vice versa. However, if there’s more than one of either portal, the opposite portal they teleport you to is the closest one. So here’s an example of how this would work:

If You had one Portal A, and 5 Portal B’s, all the Portal B’s would teleport you to Portal A, but Portal A would only teleport you to the closest Portal B. However, while that is the idea in theory, I do not know how to scan for objects in the world to find the closest one.

If anyone’s curious about the purpose of this, I’m building an action game and the Portals are one of the only Projectiles I have not finished. These Projectiles are for a character of the Setplay Archetype in which the player can spawn A and B Portals at will, and each time a portal spawns, all of the portals in the environment will check to see which one’s the closest and set their connected variable to that one. To offset how limiting this could be, the Portals also disappear after a total of 3 calls of OnBeginOverlap. I’ve got everything else taken care of, it’s mostly just the detection of the closest portal that needs addressing. It would also be called in a new event and possibly checked for via a tick.

Final Context, my Unreal Engine Version is 4.23, I’m using an older one as it is stable and comes with all the functionality I need for my game. This also means no more updates are showing up that could modify the code which will also mean that the solution provided will be more or less pretty timeless.

Thank you in advance for any responses I receive.

Providing all portals are stationary, the portal A could evaluate a pure function whenever portals B spawn or get destroyed:

Variables flagged with local_ are local variables.

If portals update their location every frame, move the GetAll node outside of this function and call it only when portals spawn / get destroyed. The rest should then either Tick or, at least, update frequently.


The ham-fisted GetAll might be enough here but more nuanced, yet more involved, methods exist.