Check if player is in an area

I have a player that is running on batteries. I’m creating power areas for him so if he is within the sphere of influence of one of these power poles then he’s being supplied with power.

I thought this would be simple but I’m having issues as follows:

Begin overlap → runs a custom event on the player that increases his energy by a given amount (works)
Begin overlap → runs a custom event on the player that decreases his energy by a given amount (works)

here’s the hard part. What if 2 of these poles overlap? The player enters the second one then leaves the first. This leaves him on battery power.
I thought I’d send the id of the current power pole so if he enters the second one before leaving the first, I can check the name and if the name is different, I set the current pole to the new pole. That worked kinda.

The issue is if he enters the second while still in the first, (he’s now in 2 areas that are overlapping), the id gets changed to the current area which should be the second, but he’s still in the first area because they are overlapping each other. Now he walks back into the first and because the id is now on the second, he’s without power.

You could do something like this:

ClockworkOcean, thank you. I have at this point only about 6 months with the engine and I didn’t know about IsOverlappingActor.

Since the player will be adding his own power poles, I had to modify your answer a bit, but it works perfectly.
For anyone interested; In the Player, I set up a few variables and some functions.

(Some things are hard coded for testing)!

As part of BeginPlay, I call GetAllPowerPoles to fill the array. If more are added, then I add them to the array. Also starting the timer function.

When the player steps into the power sphere, it sends an event to the Player that runs SearchForCurrentPower.

Next, if the Player steps out of the power sphere, it sends an event to the player that runs SearchForCurrentPower.

This is what it looks like on the Player’s side:

I only need this running if the Player enters or leaves one of the spheres.

Looks great :slight_smile: