Is there a way to destroy everything attached to a socket?

I’m trying to swap scopes on a weapon when i press a button. I am attaching the scopes to a socket on the weapon which is a component in in a character via blueprint (Spawn actor>attach to actor nodes>socket name).

   However, I have to destroy the currently attached scope when I swap to another scope. This is where I have trouble. I cannot find a way to destroy anything that is attached to the socket. I tried to destroy the actor by creating a reference to it then using it as a target. but that does not seem to destroy the actor. However I can spawn the actors successfully when swapping, though doing this multiple times slows down the game as understandable because multiple instances of the same scopes are spawned again and again without destroying the previous scope. What am I missing here?

Hey scbaradwaj.

  1. Do you really need the scope to be an actor? What about StaticMeshComponent.

  2. I’m confused why don’t you actually set your spawned scopes to variables) That’s why you can’t destroy it.

scope value 0 is for Holoscope and 3 is for sniper scope

First let me clarify, I’m new to unreal and coding in general.

  1. I need them to be actors because I’m using a screen capture 2d camera attached to the scopes for the scope zoom effect. Each scope has its own sc2d cam and placement.
  2. I promoted them to variables and then i deleted the setter, do i need to keep it in place so it will set the ref every time? I thought once I get the ref variable it was enough. I’ll try keeping them in place and get back to you

.

So, it turns out i need to set them every time. It is working when i change the scopes directly from specific keys. Its not working when I change using the next scope button. I’ll try some things and get back to you.

Also, I’m guessing there is now way to destroy everything attached to a socket?

I didn’t see on submitted screenshots that you promote actor’s reference.

Is next scope button the “1”? You didn’t change scope index before calling the function, I guess.

You can get everything attached to any component. Just remember that if you use actor components you usually need to get parent actor to get reference to scope itself (like widget stuff).

At first, i promoted them into variables and deleted the setter you get when you promote a variable due to misconception that I won’t need that setter anymore. I fixed it now though and it is working properly now. I could use the get children component as you did, but I have multiple actors attached to the same parent which I don’t want destroyed (I have the main body which has sockets for barrel, scope, magazine, and body cover). Since I want to swap only scopes at a time, and not destroy all other actors namely barrel, magazine etc… I wanted to know if it was possible to destroy all components attached to the particular socket. Now I’m using the below method to destroy them, though I don’t think it is efficient.

And here is the variables promoted

And yes, I called the function before changing the index, i fixed it now. Thanks for taking the time to help me!