I have a blueprint that only has one predefined component (an Arrow) and then the Construction Script generates a lot of additional components using functions like AddSceneComponent, AddStaticMeshComponent and AddChildActorComponent. All of these use manual attachment (AttachTo) and they are all attached to the Arrow, hierarchically. So the Arrow’s children are 4 SceneComponents, but underneath them there are a lot of components.
I am trying to write a function to destroy all of these (in preparation for re-creating them). Naively, I’d think this should work:
I checked in Debug and GetChildrenComponents returns the right stuff (4 SceneComponents), but after running this something weird happens. Some of the underlying components are deleted, some are not. Many are re-attached to Arrow. Actually, calling GetNumChildrenComponents immediately after this returns 15! Weirder yet, the 4 SceneComponents are essentially identical (save for a different transform) yet each is partially deleted differently!
I couldn’t find any documentation note hence my question: if component C is attached to B which is attached to A, what should happen with C when I call DestroyComponent on B?
I can achieve my goal by doing this (essentially keep looking for children and destroying them in a loop):
But this feels wrong :). Can anyone explain? Is this a bug?