# Iterate through actors of type

**URL:** <https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816>\
**Category:** Platform & Builds\
**Tags:** actors, unreal-engine, question\
**Created:** [April 6, 2014, 11:33pm UTC](https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816 "2014-04-06T23:33:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettclutch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@brettclutch](https://forums.unrealengine.com/u/brettclutch)\
**Post date:** [April 6, 2014, 11:33pm UTC](https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816/1 "2014-04-06T23:33:13Z")

</div>

Guys,

I searched and found this wiki post that I followed but can’t get it work. I suspect the wiki is out of date or has invalid code samples to begin with as I don’t understand the c++ code sample.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

Basically the goal is to iterate through all the player starts in the game and pick a random one. I don’t understand this for loop construct or how this magical “ActorItr” comes from and neither does my compiler.

What am I missing? → I’ll attempt to add to wiki once solves. Thanks Guys.

```
AScepterCamera::AScepterCamera(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	for (FActorIterator ActorItr<APlayerStart>(()); ActorItr; ++ActorItr)
	{
		this->SetActorLocationAndRotation(ActorItr->GetActorLocation(), ActorItr->GetActorRotation(), false);
	}
}

```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 7, 2014, 2:31am UTC](https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816/2 "2014-04-07T02:31:01Z")

</div>

you should not being using () or doing stuff in relation to larger world environment in your constructor!

move this into Post Init and you should be fine

also you should always post compile errors if you are getting any

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [April 7, 2014, 3:05am UTC](https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816/3 "2014-04-07T03:05:15Z")

</div>

For some reaon 's method seems to be outdated and FActorIterator make error like the template on it does not exist in it anymore… instead i found TActorIterator which seem to work

```
//in h in class

TArray<APlayerStart*> SomeArray;

//in cpp
for (TActorIterator<APlayerStart> ActorItr(()); ActorItr; ++ActorItr)
{
        SomeArray.push(*ActorItr);
}

```

Push all PlayerStart pointers to array as i showed and then randomly pick one of them from array ;]

And as said, you should not use that in constructor not only world pointer in () is most likely initiated which will cause the crash, but also your PlayerStart won’t exist at that point in game memory. Do it in BeginPlay() or PostInit()

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 7, 2014, 10:17am UTC](https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816/4 "2014-04-07T10:17:17Z")

</div>

instead i found TActorIterator which seem to work

I myself dont know what I still had FActorIterator in some parts of my code

I looked at this post twice thinking,… “FActorIterator?”

I will go update my wiki page now, thanks !

PS: though I just checked and FActorIterator still compiles for me… strange 🙂

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [April 7, 2014, 1:33pm UTC](https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816/5 "2014-04-07T13:33:37Z")

</div>

No problem 🙂

---

<div class="post-metadata">

**Author:** ![brettclutch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@brettclutch](https://forums.unrealengine.com/u/brettclutch)\
**Post date:** [April 7, 2014, 2:26pm UTC](https://forums.unrealengine.com/t/iterate-through-actors-of-type/279816/6 "2014-04-07T14:26:13Z")

</div>

Thanks guys makes sense now.
