# Get all actors of class/casting can only modify one array instance per cast? (lights and lightswitch)

**URL:** <https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664>\
**Category:** Rendering\
**Tags:** get-all-actors-from-, unreal-engine, cast, Blueprint, question\
**Created:** [August 14, 2015, 1:42pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664 "2015-08-14T13:42:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoshieZombie](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joshiezombie/32/493945_2.png) [@JoshieZombie](https://forums.unrealengine.com/u/JoshieZombie)\
**Post date:** [August 14, 2015, 1:42pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664/1 "2015-08-14T13:42:01Z")

</div>

I’ve got a light switch set up in my project with two blueprints: Lights\_BP, and LightSwitch\_BP.  
Upon overlap event I enable input. If I then hit E it will turn on my light. If I hit E again, my light will turn off. It works great with a single light, but I would like to be able to turn on and off an array of lights I place in my room.  
I’ve included a screenshot of my lightswitch\_BP and Lights\_BP

I’d like to be able to \>Get all actors of class\>all instances\>cast to lights\_BP\>Set Targets  
If this is not a reasonable idea or way of going about such things advice is appreciated 🙂

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/6/5/36537510462b38a2cfceabe9158767e0030a8c1b.png) ](https://i.imgur.com/RLjuRkx.png)

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/c/3/ec3c68523b90401830997109b0f0eefd38651462.png) ](https://i.imgur.com/LP5eLCn.png)

lights in question:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/7/097abeee97b68732d4942bc60a83c625b395ee04.jpeg) ](https://i.imgur.com/34PNP3n.jpg)

---

<div class="post-metadata">

**Author:** ![Elewyth](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Elewyth](https://forums.unrealengine.com/u/Elewyth)\
**Post date:** [August 14, 2015, 2:02pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664/2 "2015-08-14T14:02:23Z")

</div>

Hi JoshieZombie

Placing a “ForEachLoop” after GetAllActorsOfClass should do the trick. Simply connect the the top Execution line and the Array-Element with the cast to Light\_BP node. The Blueprint should then iterate over all elements in the Actor-Array, cast each element and switch on/off the light accordingly.

-Elewyth

---

<div class="post-metadata">

**Author:** ![JoshieZombie](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joshiezombie/32/493945_2.png) [@JoshieZombie](https://forums.unrealengine.com/u/JoshieZombie)\
**Post date:** [August 14, 2015, 2:22pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664/3 "2015-08-14T14:22:49Z")

</div>

Hello Elewyth!  
I’ve done what you mentioned as shown below, but it seems to hang on the last element in the array. If I place three lights it only toggles the last light that was placed. Is this possibly due to me having connected this to the overlap event? I feel like it’s only looping once when I enter the overlap box.

[http://i.imgur.com/LXBWD8k.png](http://i.imgur.com/LXBWD8k.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2ed5b4c7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2ed5b4c7](https://forums.unrealengine.com/u/anonymous_user_2ed5b4c7)\
**Post date:** [August 14, 2015, 2:25pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664/4 "2015-08-14T14:25:16Z")

</div>

Hi!

If you work with array, then you should use ForEach Loop node for change attributes in more than one object.

 ![54153-lightarray.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/3/a/43a0bfc3b5ecaeefb60e055a46c6ec4d3f7c3386.png)

---

<div class="post-metadata">

**Author:** ![JoshieZombie](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joshiezombie/32/493945_2.png) [@JoshieZombie](https://forums.unrealengine.com/u/JoshieZombie)\
**Post date:** [August 14, 2015, 2:45pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664/5 "2015-08-14T14:45:28Z")

</div>

Thank you! This is what Elewyth suggested. Your comment helped me figure out my event mistakes though. I’ve got it running smoothly now 🙂

---

<div class="post-metadata">

**Author:** ![JoshieZombie](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joshiezombie/32/493945_2.png) [@JoshieZombie](https://forums.unrealengine.com/u/JoshieZombie)\
**Post date:** [August 14, 2015, 2:58pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664/6 "2015-08-14T14:58:14Z")

</div>

Okay I’m back with another part to this question! I hope it is an easy thing to do!  
I have trigger volumes set up in each room of my house. I was thinking I could use these to group which lights turn on and off. Do you know of a way I could go about doing this?  
EDIT  
Solved using enumerators!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2ed5b4c7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2ed5b4c7](https://forums.unrealengine.com/u/anonymous_user_2ed5b4c7)\
**Post date:** [August 14, 2015, 3:33pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-casting-can-only-modify-one-array-instance-per-cast-lights-and-lightswitch/328664/7 "2015-08-14T15:33:09Z")

</div>

Try to use **Tag** attribute

 ![54160-lighttag01.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/2/af2b8c4b1221350eeb59c99064b4ecdcab6692a7.png)

And to **LightSwitch\_BP** add variable and condition.

 ![54161-lighttag02.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/2/b/f2b72a1d4bfaf83d00281c8ed3a2989efb2ad258.png)

All you need, is set tag for the lights and for the volume.
