Plugin Programming: How do I iterate actors spawned dynamically in a plugin?

I’m trying to write a plugin that iterates all of actors which are spawned by host project during runtime.
Following line of code returns only the actors that are dropped before hitting play button since it’s static function.


**static void IterateActors(UWorld* Context, TArray<Actors*> &OutActors); **

The class used is


**UBlueprintFunctionLibrary**

. Is there anyway to read dynamically spawned actors via plugin code.

I referred many tutorials, but none of them gives more clarity.

Any help is greatly appreciated. Thanks in advance…

Use TActorIterator with the *Context uworld:

A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine ForumsObject%26_Actor_Iterators,_Optional_Class_Scope_For_Faster_Search

Hi,

Thank you for answer, i already gone through that wonderful tutorial. It works very well in standalone game.

I’m trying to iterate all characters in the world, Scoped Iterator (scoped to ACharacter) is always empty.

These observations may help:

  1. Characters are spawned by another plugin
  2. GetWorld() is not null
  3. Iterator is defined in begin play in a plugin class (of type AActor), i dropped this actor into PIE to execute it’s begin play function.

Code in BeginPlay usually is executed before anything was spawned.

Execute iterator code manually instead of relying on BeginPlay.

It makes sense. How to iterate only after all characters are spawned. I guess that should be a separate question. Thank you very much for the information.

why not do whatever it is you need to do at the time you spawn the characters, instead of spawning then doing it all?