# Get All Actors Of Class not working with Decal Actor

**URL:** <https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519>\
**Category:** Rendering\
**Tags:** Destroy, foreachloop, unreal-engine, Decals, UE4, Blueprint, question\
**Created:** [December 18, 2017, 2:35am UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519 "2017-12-18T02:35:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ForemanDesigns](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ForemanDesigns](https://forums.unrealengine.com/u/ForemanDesigns)\
**Post date:** [December 18, 2017, 2:35am UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/1 "2017-12-18T02:35:38Z")

</div>

I am trying to delete all decals in the level via a For Each Loop. I’m using the “Get All Actors Of Class” to attempt to find all decals but it doesn’t work - the debug log prints that it looped 0 times meaning it didn’t find anything. Here’s my level blueprint:

 ![224195-ue4-destroy-decal-actor-issue-01.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/6/af68b69a83fe79fbcc220daf4ad676bea3aba8b6.png)

Note that no decals are initially created when the map loads, but the decals are being created via “Spawn Decal at Location” when an actor is destroyed, like so:

 ![224196-ue4-destroy-decal-actor-issue-02.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/7/c/e7c479fec7e05b73a79823265ba2be3b19ffd178.png)

This method works great when deleting objects of a different class than “Decal Actor”, but not with decals that have been spawned at a location. Could someone please help me get this working?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 18, 2017, 10:48am UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/2 "2017-12-18T10:48:11Z")

</div>

I haven’t worked with decals much but looking at the return type, it seems that a decal is not an actor but a component. Try it like this and see if that helps:

![224236-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/2/9/c294f88625895907d6155eed851a459982a17428.png)

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 18, 2017, 12:22pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/3 "2017-12-18T12:22:05Z")

</div>

Hey there, Spawn Decals doesn’t create a DecalActor, but instead creates a Decal Component. Since you are using Spawn Decal At Location then that means that he adds the decal component to the World Settings actor that is inside the GetWorld(). The problem is that i don’t think you can access that in Blueprints, you would need to create a get function in c++ that would do that for you, something like:

```
TArray<UDecalComponent *> AYourActor::GetDecalComponents()
{
    TArray<UDecalComponent *> DecalComponents;

     if(GetWorld() != nullptr && GetWorld()->GetWorldSettings() != nullptr)
     {
         TArray<UActorComponent *> ActorComponents = GetWorld()->GetWorldSettings()->GetComponentsByClass(UDecalComponent::StaticClass());

         for(UActorComponent * ActorComponent : ActorComponents)
         {
              UDecalComponent * DecalComponent = Cast<UDecalComponent>(ActorComponent);

              DecalComponents.Add(DecalComponent);
         }
     }

     return DecalComponents;
}

```

If you want to do the decal array construction in blueprints then just do this:

```
AWorldSettings * AYourActor::GetWorldSettings()
{
     if(GetWorld() == nullptr)
         return nullptr;

     return GetWorld()->GetWorldSettings();
}

```

And in blueprints do GetComponentsByClass node and foreach ActorComponent just cast it to DecalComponent and do whatever you want to do.

---

<div class="post-metadata">

**Author:** ![ForemanDesigns](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ForemanDesigns](https://forums.unrealengine.com/u/ForemanDesigns)\
**Post date:** [December 18, 2017, 6:48pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/4 "2017-12-18T18:48:22Z")

</div>

Oh, wow! Well thank you for the help - I appreciate it but I am a beginner so unfortunately I don’t have any C++ experience yet. Maybe I can try to stumble my way through the C++…

I can’t accomplish what I’m trying to do purely with blueprints though?

If not, is there a way to spawn a decal differently so it is exposed to BP?

---

<div class="post-metadata">

**Author:** ![ForemanDesigns](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ForemanDesigns](https://forums.unrealengine.com/u/ForemanDesigns)\
**Post date:** [December 18, 2017, 6:49pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/5 "2017-12-18T18:49:23Z")

</div>

Unfortunately this does not work. Probably due to the reason that xlar8or said. ☹

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 18, 2017, 6:56pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/6 "2017-12-18T18:56:11Z")

</div>

I think i’ve found a way. If you do a Get All Actors of Class with World Settings it should work.

---

<div class="post-metadata">

**Author:** ![ForemanDesigns](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ForemanDesigns](https://forums.unrealengine.com/u/ForemanDesigns)\
**Post date:** [December 18, 2017, 7:16pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/7 "2017-12-18T19:16:26Z")

</div>

I’ll give this a shot tonight and see if I can get it working!

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 18, 2017, 7:19pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/8 "2017-12-18T19:19:21Z")

</div>

Surething, dont forget that you still need to do Get Components by Class of UDecalComponent from the World Settings actor.

---

<div class="post-metadata">

**Author:** ![ForemanDesigns](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ForemanDesigns](https://forums.unrealengine.com/u/ForemanDesigns)\
**Post date:** [December 18, 2017, 7:27pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/9 "2017-12-18T19:27:33Z")

</div>

If it’s not too much trouble would you mind taking a quick blueprint screenshot?

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 18, 2017, 8:04pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/10 "2017-12-18T20:04:50Z")

</div>

Here you go, i just get the first World Settings actor if its valid and then get all the decalcomponents attached to it.

 ![224295-decals.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/d/4/5d414b32ad0f157a9c93e90914fbc1ea8247031b.png)

---

<div class="post-metadata">

**Author:** ![ForemanDesigns](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ForemanDesigns](https://forums.unrealengine.com/u/ForemanDesigns)\
**Post date:** [December 19, 2017, 4:47am UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/11 "2017-12-19T04:47:36Z")

</div>

This works great! Thank you so much! 🙂

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 19, 2017, 10:46am UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/12 "2017-12-19T10:46:53Z")

</div>

You are welcome 🙂

---

<div class="post-metadata">

**Author:** ![Jgxxxx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jgxxxx](https://forums.unrealengine.com/u/Jgxxxx)\
**Post date:** [May 13, 2024, 7:16pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/13 "2024-05-13T19:16:09Z")

</div>

Have they changed this? This no longer works

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [May 14, 2024, 8:52am UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/14 "2024-05-14T08:52:59Z")

</div>

It’s working fine for me:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/8/b2882a7b149fd50e01692fe60c04d047e527ee48.png)

---

<div class="post-metadata">

**Author:** ![Jgxxxx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jgxxxx](https://forums.unrealengine.com/u/Jgxxxx)\
**Post date:** [May 15, 2024, 5:50pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/15 "2024-05-15T17:50:27Z")

</div>

Are you on 5.4?  
It finds world settings and decal component, but when I destroy actor it does nothing and decals are still there.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [May 15, 2024, 6:32pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/16 "2024-05-15T18:32:58Z")

</div>

Yes, I’m on 5.4. Don’t you mean destroy the component, and not the actor? Can you show me your code?

---

<div class="post-metadata">

**Author:** ![Jgxxxx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jgxxxx](https://forums.unrealengine.com/u/Jgxxxx)\
**Post date:** [May 15, 2024, 7:03pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/17 "2024-05-15T19:03:41Z")

</div>

![destroy decals](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/1/e/f1e82df1048eedfab614454086c79686ac7e82cc.jpeg)

Ah yes, component, my bad.

EDIT: Oh it actually removes ONE decal every time I run it… not sure how to get it to remove all…

EDIT2: So if I spawn in 2 decals, I have to run it twice to get rid of both of them, if I spawn in 10 decals I have to run it 4 times for all of them to disappear… something really strange going on

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [May 15, 2024, 7:58pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/18 "2024-05-15T19:58:27Z")

</div>

I’m assuming you are executing that code at runtime. Can you also put a print after the Destroy Component to make sure it’s being executed?

As a side note: You don’t need that branch, because if the array is empty the For Each Loop will leave immediately.

---

<div class="post-metadata">

**Author:** ![Jgxxxx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jgxxxx](https://forums.unrealengine.com/u/Jgxxxx)\
**Post date:** [May 15, 2024, 8:29pm UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/19 "2024-05-15T20:29:30Z")

</div>

it is executing, I get print messages, I spawned in loads of decals and first run it removes maybe 30 of them, and then it seems to pretty much half every time I run it until they’re all gone.  
Also removed the valid branch.  
I use spawn decal at location to spawn them in, could that be causing this? Is there even another way to spawn them in?

Edit: Added a counter and yes it is removing exactly half of them each time I execute it …??

Edit2: I think I figured out why this is happening…  
When I delete a decal the decal above it in the array gets moved down to the deleted position and then the For loop counts up and moves on to the second decal, which used to be the third…  
I have no idea if this is how it works, but this is the only way I can make sense of why this is happening. I will try to put all decal components into an array first and then delete them when i have time.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [May 18, 2024, 11:14am UTC](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519/20 "2024-05-18T11:14:07Z")

</div>

You should use a Reverse For Each loop for these cases where the array is being changed while looping, that way you remove from the end and work your way to the beginning without needing to duplicate the array.

[Next page](https://forums.unrealengine.com/t/get-all-actors-of-class-not-working-with-decal-actor/412519.md?page=2)
