Download

How to catch when a child component is added in the editor

I have a custom actor class that can have either a static mesh, a skeletal mesh, or combinations of the two. I want to have specific default values set when the mesh is added in the editor. Those values are different for skeletal and static meshes, and are somewhat different than the defaults generated when a mesh is created. I want to set these defaults programmatically to avoid having to have content creators set them by hand, which can be easily forgotten.

My initial take was to create a ‘mesh holder’ component that inherits from UMeshComponent which is created with the actor. The desired mesh would then be added as a child of the ‘mesh holder’, and an overridden method that would fire when the child mesh is added. Because my actor can have a combination of meshes, I want to catch whenever a mesh is added.

The problem is that I can’t seem to find which method to override when the actual mesh is added in the editor. Is there such a method called when a child component is added, or is there a better approach to set those defaults consistently?

Thanks in advance.

UActorComponent::OnRegister | Unreal Engine Documentation
USceneComponent::OnAttachmentChanged | Unreal Engine Documentation


class MY_API UMyCMP : public USceneComponent {
    //...

#if WITH_EDITOR
	virtual void OnRegister() override;
	virtual void OnAttachmentChanged() override;
#endif

}

When you attach a scene component or create one, the editor call those methods on your component class.


But for what you’re saying, I think you want something like this:
AActor::PostEditChangeProperty | Unreal Engine Documentation

The editor will re-run your Construction Script whenever a change is made in the editor.
You can use this to detect what the configuration is and set up defaults as appropriate.

Thanks! It’s pretty simple when you start thinking in Unrealesque (Unrealistic?) terms. :slight_smile: