Bp ActorComponent from c++ in Bp Actor from c++ seems [bugged /corrupt]

I just went through the same journey as described in your posts here. At first I was excited that I can just define my own component class. Then: it crashed on next startup (live coding worked until then). My search eventually led me here and I find it very sad that it turns out this feature is simply not supported: you simply can’t define a BP class for a component class -yet the editor sugget you could pick a BP class. Definitely, this is an engine bug! At least until they official support this feature - which imo they should.

Here is the UE5 tooltip btw so people can find this thread more easily:
“The class to use when creating this component for this class. This can only be done for components defined in native at this time.”

My solution was:

  • BP C++ classes that should contain the component now don’t directly spawn the component but get an interface inherited that includes a getter for the component. (Makes it accessible by C++)
  • The BP C++ classes which inherit this “component owner interface” store a pointer to the component
  • In the parent BP i add the component manually
  • In the BP event graph, on beginplay, i save the BP component to the C++ component pointer

This way I have a contract that the component can be returned from those classes, but i have freedom regarding how or when i add this as long as its a subtype of that C++ component type. It is a few extra steps in the BP but that’s quite acceptable.

Here is my interface:


UINTERFACE(BlueprintType, meta=(CannotImplementInterfaceInBlueprint))
class ULgcHighlightableEntityInterface : public UInterface
{
	GENERATED_BODY()
};

class ILgcHighlightableEntityInterface
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable)
	virtual void SetHighlightableEntityComponent(ULgcHighlightableEntityComponent* InHighlightableComponent) = 0;
	
	UFUNCTION(BlueprintCallable)
	virtual ULgcHighlightableEntityComponent* GetHighlightableEntityComponent() = 0;

	virtual const ULgcHighlightableEntityComponent* GetHighlightableEntityComponent() const = 0;
	
	UFUNCTION(BlueprintCallable)
	virtual void SetHighlightableMeshes(const TArray<UMeshComponent*>& InHighlightableMeshes);
};

It is quite generic except for the SetHighlightableMeshes function which is quite unique and I use to to trigger an event on the components, if the component is not nullptr :wink:

1 Like