I’m creating a SceneComponent followed by 2 StaticMeshComponents. I have a RoomMesh that is editable so the user can define what mesh to use. As soon as the user does that I would like it to rebuild the entire “region” by using the new mesh components. I was under the impression that the entire actor is reconstructed, however, my existing components stay while it appends additional components. Is this the desired behavior? If so, what is the proper way to remove/cleanup the components before rebuilding them?
Hey, the way i do it is by using DestroyComponent() at the start of OnConstruction on every Component that i create in it, it works fine for me. You could try this as well : EComponentCreationMethod::SimpleConstructionScript.
You have to unregister them. That or destroy the actor, which does the same. From what I can tell, the code keeps the components registered even if you recall the construction, unless the actor gets destroyed, which will call the various component’s unregister functions, or you do it manually.
As Raikoh said, Calling destroy works as well, as it just calls the UnregisterComponent function on its own. Note: DestroyComponent only works on the actor it is called from, so you cant call it from another class, unless you use delegates.