How to check if an actor is inside a proximity?

Hello,

I need a way to check when an actor enters a proximity which has a specific radius and call a function when it enters the area.

What are the ways to do that?

Thanks.

you can you a sphere as trigger and call OnBeginOverlap
this may help you

1 Like

Depending on the context, you can implement a ticking check for distance. I imagine this is much heavier performance-wise, but technically, whenever you actor moves, you can calculate it’s distance to the area by simple vector subtraction, then you have a simple if statement for function calling. This might be useful if, for some reason, creating a triggervolume isn’t doing the job right. But try the volume first!

You can use the example code that I posted in my thread here

It shows the method where you create a sphere component and detected actors entering/leaving the sphere. It requires you to declare a USphereComponent* variable in your actor class (in my case its RespawnSphere). It works perfectly except when actors are potentially spawned inside the sphere, but as long as they are spawned outside they are always detected when entering and leaving the sphere

That seems to do the trick but it’s weird that it doesn’t detect it when the actor spawns inside the sphere. I beleive it’s because the actors are initalized before the sphere, is there any fix on this?

You mean using BeginOverlap and EndOverlap?

Essentially how I understand BeginOverlap will be only triggered if its beginning to overlap but it wont be persistent or in other words updated the presents, just triggering once the sequence after Overlapping, same with ending it.

If you size down the sphere so it overlaps with the Actor and than destroy it, you will see that Begin and EndOverlap will be triggered.

So if you need to have something that updates and checks if that object is within a certain bound, the only thing I would think of is using a Sweep that is always updating.

The topic is a bit old, but I’ve included a video about it so it can help others.