Template mismatch when attaching a spawned actor to a socket

Hi there

I’m trying to attach by this line of code…

ow_oEquippableObjectActor->GetMeshComponent()->AttachTo(m_player->GetMesh(), *socketName, EAttachLocation::SnapToTarget, true);

…an object (ow_oEquippableObjectActor) spawned in this way:

spawnedObject = World->SpawnActor<APickableObjectActor>(m_classOfThisObject, SpawnLocation, SpawnRotation);


UPROPERTY(EditDefaultsOnly, Category = "Pickable Object")
		TSubclassOf<class APickableObjectActor> m_classOfThisObject;

and ow_oEquippableObjectActor is an object of the class AEquippableObjectActor which is child of APickableObjectActor

The attaching function is called by an object (m_inventoryWrapper) located in my character class:


declared in the header file of my character class:

UInventoryWrapper* m_inventoryWrapper; //UObject child

and instanced

m_inventoryWrapper = CreateDefaultSubobject<UInventoryWrapper>(TEXT("Inventory Wrapper"));

the error output is:
Template Mismatch during attachment. Attaching instanced component to template component. Parent ‘CharacterMesh0’ Self ‘Mesh’

I can’t understand why if I omit the UPROPERTY() line, the attachment works properly, but the garbage collector destroys my unreferenced object (m_inventoryWrapper) in about 20 seconds, so I cannot omit that line.

Can anyone please help me?

Let me know if you need a better explanation.