Best way to find specific actor in world?

Using actor iterator is fine here. Just do it on BeginPlay() and store refs. No performance hits and no need to manually link in editor. For a non-trivial amount of lights it is the only reasonable way to do it.

Example where the player controller needs a reference to an “AreaLightingController”, exactly one of which is in each level. This is also a case where it is not possible to manually link things in the editor - player controllers don’t exist until the game starts.



 for (TActorIterator<AAreaLightingController> ActorItr(GetWorld()); ActorItr; ++ActorItr)
 {
  _areaLightingController = Cast<AAreaLightingController>(*ActorItr);
  if (_areaLightingController)
  {
   LOG("APrimaryPlayerController: GetAreaLightingController(): controller found!");
   return;
  }
 }


2 Likes