Get all of a specific actor

You’re using the iterator correctly, you’re just using the wrong template parameter. Remove the * from your TActorIterator line.

Also, in what function are you running the iterator?

Hey everyone,

So currently I am trying to implement a simple spawning system. Taking an array of actors, generating a random int and using that as an index to get a location from the actor. I am just having an issue of getting all of the actors in the world. Is there an easy way to do this? I have searched and found something called Actor Iterators? I’ve tried but it’s not really working and I dont think i understand how they work :stuck_out_tongue: Any assistance would be awesome!

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Waves")
		TArray<AAuroraAISpawnPoint*> spawnLocations;

// Get all actors
	for (TActorIterator<AAuroraAISpawnPoint*> ActorItr(GetWorld()); ActorItr; ++ActorItr)
	{
		// Add the actor to our spawn locations array
		spawnLocations.Add(ActorItr);
	}

I need to get all the instances of AAuroraAISpawnPoint and add them to my array, a little confused on this one thanks!

Hi ,

Check the following link: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

Also, another way:

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

You will get on FoundActors all actors of AYourActorClass

Best regards

This worked like a charm! :slight_smile: Is there any way to cast an array?

Hi ,

You can loop over FoundActors and then cast each element. For example:

for(AActor* Actor : FoundActors)
{
	MyActorClass* MyActor = Cast<MyActorClass>(Actor);
	if(MyActor)
	{
		//... do something
	}	
}

Cheers