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:
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:
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?
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:
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:
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?
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
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.
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.