UStaticMeshComponent OnStaticMeshChanged

Hello guys,

I am trying to connect to an EventDispatcher with C++ on the StaticMeshComponent. I have red that I should use AddDynamic to reference to a delegate within my class. However, I am getting the following error:

'__Internal_AddDynamic': is not a member of 'UStaticMeshComponent::FOnStaticMeshChanged'

This is the code in question, I believe the .h file will speak for itself:


	UPartMeshComponent::UPartMeshComponent() {

		StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Part Mesh Component"));

		StaticMesh->AttachToComponent(this, FAttachmentTransformRules(EAttachmentRule::KeepRelative, false));

		StaticMesh->OnStaticMeshChanged().AddDynamic(this, &UPartMeshComponent::OnStaticMeshChanged);

	 }

	void UPartMeshComponent::OnStaticMeshChanged(UStaticMeshComponent* component) {

		UE_LOG(PartLog, Log, TEXT("%s::OnStaticMeshChanged()"), *GetName());

	 }

I am doing something obviously wrong can someone point me in the right direction?

Found out that I had to use the AddUObject.

I changed line 7 to:

StaticMesh->OnStaticMeshChanged().AddUObject(this, &UPartMeshComponent::OnStaticMeshChanged);

And it worked!