Binding actor components like widgets?

In a UMG UUserWidget subclass you can mark a widget UPROPERTY with the meta tag BindWidget, and then in a Blueprint subclass of your UUserWidget subclass, when you click Compile on the blueprint in the editor, if you haven’t created a widget of that name, you’ll get an error.

Is it possible to do something similar with the components of an actor? I would like to define a component UPROPERTY in my AActor subclass, and then “bind” it to a component added in a blueprint subclass.

The closest I’ve gotten is something like:

void AMyActor::PostInitializeComponents()
{
    Super::PostInitializeComponents();
    MyComponent = FindComponentByClass<UMyComponent>();
    check(IsValid(MyComponent));
}

but PostInitializeComponents isn’t called until the instance spawns in game.

Is there any way to set the component in the editor in the blueprint subclass and for the blueprint to not compile if it hasn’t been set (like BindWidget) ?

While I have not found a way to do this exactly, I am very curious also if this is possible as it would be very nice,

I offer an alternative solution (2 years later… sorry) too you and to anyone else who finds this topic.
I have found that is is easiest to create a ‘linked’ component in your C++ class initially before a BP is ever created:

In example.h

UCLASS()
class EXAMPLE_API AExampleLinkedComponent : public AActor {
public:
	//Class Constructor
	AExampleLinkedComponent();

	//Replace UStaticMeshComponent with any USceneComponent Derived Class
	UPROPERTY()
	TObjectPtr<UStaticMeshComponent> CExample = nullptr;

private:

	GENERATED_BODY()
}
In example.cpp

//Class Constructor
AExampleLinkedComponent::AExampleLinkedComponent() {
	//Replace UStaticMeshComponent with any USceneComponent Derived Class
	CExample = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyComponentName"));
	
}

This creates a default a component of the specified type (in this case a Static Mesh Component) in your derived BP Actor

Now if you want to Edit the component you can edit it directly in the C++ at any time and the changes should be reflected during runtime or in the BP editor window,
or you can make functions so you can edit its values in a BP script, or edit them directly in the details panel.

While the Scene Components are not ‘Linked’ the C++ in a way ‘owns’ the component at the very least having a pointer to it which does allow you to manipulate the component from C++ or BP code.

While this is not a exact solution to your issue, I believe it should serve well enough for most applications
:slight_smile: