Is there a nice way to destroy a component that is spawned by a component, from within the component that spawned it?

Pretty simple really; I have a component that spawns another component from within it on its owning actor. When this component destroys, I’d like its spawned component to destroy too; but I cannot do that from the component’s End Play as it must be destroyed by the owning object, which is the Actor the component is on.

I’d like to avoid having to make the actor bear the brunt of destroying both components, but if I have to do that it’s not a huge problem. Just a bit ugly (I’d likely add a function to the main component that returns an array of components that should be destroyed along with itself, so the Actor can call ‘Get Associated Components’ > ‘Destroy Components’ or some such.

Have you considered spawning an Actor and spawn the components on this? Then the spawning component just needs a reference to the Actor and it can be destroyed along with its components.

It would also work with an array of component references but having a lot of components on one Actor is generally not easy to manage and can affect performance in some cases.

1 Like

I hadn’t, thanks. Hmm, I could do it like that with some refactoring, though said component is nice to have as a component for other purposes so I’d need a sort of container-actor for that usage. It’s a good idea, I’ll have a think about it, thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.