How find nearby Actors in C++

I’m fairly new to Unreal. I’m interested in Actor/Actor interactions for simulations. I intend to build automata that interact with each other. This means I need to see which Actors are “near” each other in a scene. How do I detect other nearby Actors using C++

You can filter the results down to find the closest one like in SenToRious example or anything else you have in mind like only the ones in front of you or any arbitary Angle. Simple Math basicly in most cases.

Ofcourse you can also use Begin & End Overlap to add and remove any Actors that come in Range.

Hmm thats pretty standard stuff. Create a SphereComponent, Setup Collisions properly, Radius is basicly your Range. USphereComponent | Unreal Engine Documentation

If you just want to get a Global List of avaivable Actors in your Scene you can use this static Method. But be aware that this is not cheap to execute on a frequently :stuck_out_tongue_winking_eye: I highly recommand to go the Physics based approach.

If an actor needs to see another actor as if they had eyes I would look into trace scans or look into learning AI in UE4.
To get the distance between two actors you can do this:

float Distance = (myActor1->GetActorLocation() - myActor2->GetActorLocation()).Size();

Thanks, is there a global list of objects myActor1 should have access to? In the Blender Game Engine, you can do for obj in scene.objects. Is there a similar list in UnReal? Thanks!

I understand the math bits, I don’t know how to find the list of possible objects. Do you have a complete example lying about by any chance?

There are multiple ways of doing it but there’s a function that gets you an array of all actors of a specific class then you can loop and check their locations etc
Function is:

TArray<AActor*> FoundActors;
     UGameplayStatics::GetAllActorsOfClass(GetWorld(), YourClass::StaticClass(), FoundActors);

Not standard stuff to me, been programming in Unreal for about 10 hours. Do you have a simple example I could reference? I’d appreciate it.