# Help with cycling through actors in a fixed order?

**URL:** <https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389>\
**Category:** C++\
**Tags:** actor, sorting, unreal-engine, Array, CPP, question\
**Created:** [September 4, 2021, 6:22pm UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389 "2021-09-04T18:22:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samathan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/samathan/32/1058905_2.png) [@Samathan](https://forums.unrealengine.com/u/Samathan)\
**Post date:** [September 4, 2021, 6:22pm UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389/1 "2021-09-04T18:22:12Z")

</div>

So I have a 1 versus 1 board game, and there are 5 actors of type “map camera”. One on each side of the board, and one at the top looking down. Each player starts at the camera facing their side of the board. Each map camera actor has a variable called “camera type”, which is an enum of either front, back, right, left, or top. I want each player to be able to cycle through each camera in a fixed order (i.e. front, right, back, left, top) by pressing one “cycle” button, but I’ve tried a bunch of different implementations of this, and I can’t figure it out. I also wanted the order to change depending on the player, so the player at the front of the board needs to go front, right, back, etc. but the player at the other side of the board needs to go back, left, front, etc. Does anyone have any ideas?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Jaco001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jaco001](https://forums.unrealengine.com/u/Jaco001)\
**Post date:** [September 4, 2021, 6:38pm UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389/2 "2021-09-04T18:38:19Z")

</div>

2 arrays. One for each one player.

---

<div class="post-metadata">

**Author:** ![Samathan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/samathan/32/1058905_2.png) [@Samathan](https://forums.unrealengine.com/u/Samathan)\
**Post date:** [September 4, 2021, 7:30pm UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389/3 "2021-09-04T19:30:30Z")

</div>

Could you elaborate?

---

<div class="post-metadata">

**Author:** ![Jaco001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jaco001](https://forums.unrealengine.com/u/Jaco001)\
**Post date:** [September 4, 2021, 7:35pm UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389/4 "2021-09-04T19:35:32Z")

</div>

Make 2 arrays with 5 actors in correct order (not much work and easy to do). At beginning of play give reference of array to corect player. Cycle thru array for each player can be same.

---

<div class="post-metadata">

**Author:** ![Samathan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/samathan/32/1058905_2.png) [@Samathan](https://forums.unrealengine.com/u/Samathan)\
**Post date:** [September 5, 2021, 12:20am UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389/5 "2021-09-05T00:20:50Z")

</div>

But I’m not sure how to get the arrays in the order I want. When I use GetAllActorsOfClass(), it puts them all into an array in a random order.

---

<div class="post-metadata">

**Author:** ![Jaco001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jaco001](https://forums.unrealengine.com/u/Jaco001)\
**Post date:** [September 5, 2021, 7:32am UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389/6 "2021-09-05T07:32:01Z")

</div>

1. If so you can ‘sort’ array using locations of actors
2. or just manualy spawn actors and put them into array with corect order.

 ![348002-pic7.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/b/d/3bdb1fe5c6b84570eeba282dfcedf188ae42e502.png)

---

<div class="post-metadata">

**Author:** ![Samathan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/samathan/32/1058905_2.png) [@Samathan](https://forums.unrealengine.com/u/Samathan)\
**Post date:** [September 5, 2021, 4:20pm UTC](https://forums.unrealengine.com/t/help-with-cycling-through-actors-in-a-fixed-order/488389/7 "2021-09-05T16:20:33Z")

</div>

Interesting, thanks!
