Hi,
I’d like to attach an AActor to a Socket of a Character Mesh (actually nothing special). This leads to the followingI have the following Ensure condition failed:
LogOutputDevice: Error: Template Mismatch during attachment. Attaching instanced component to template component. Parent 'CharacterMesh0' (Owner 'Default__BP_ThirdPersonCharacter_C') Self 'StaticMesh' (Owner 'BP_Gun_C_UAID_7085C272D161757801_1718746471').
These are the relationships:
-
Has a:
ATheThirdPersonGameCharacter
→UInventoryComponent
→USocketStorage
→ Reference toUInventoryComponent
-
Calls:
UInventoryComponent::Add(...)
→UInventoryComponent::AttachToCharacter(..)
→ATheThirdPersonGameCharacter::AttachToSocket(...)
→AActor::AttachToComponent(...)
Any suggestions why this could happen and how I can resolve the issue?
tl;dr
ATheThirdPersonGameCharacter
class ATheThirdPersonGameCharacter : public ACharacter
{
private
UPROPERTY(..., meta = (AllowPrivateAccess = "true"))
TObjectPtr<UInventoryComponent> InventoryComponent;
}
void ATheThirdPersonGameCharacter::AttachToSocket(AActor* Actor, FName SocketName) const
{
const FAttachmentTransformRules AttachmentTransformRules(
EAttachmentRule::SnapToTarget,
EAttachmentRule::SnapToTarget,
EAttachmentRule::KeepWorld,
false);
Actor->AttachToComponent(GetMesh(), AttachmentTransformRules, SocketName);
}
UInventoryComponent
class ..._API UInventoryComponent : public UActorComponent
{
private:
UPROPERTY() TObjectPtr<USocketStorage> Melee1;
}
void UInventoryComponent::AttachToCharacter(APickup* Pickup, EStorageName StorageName)
{
const FName SocketName = *StorageSocketMap.Find(StorageName);
CharacterOwner->AttachToSocket(Pickup, SocketName);
}
USocketStorage : UStorage
class ..._API UStorage : public UObject
{
UPROPERTY()
TObjectPtr<UInventoryComponent> InventoryComponent;
void USocketStorage::Add(APickup* Pickup, FStorageInfo& StorageInfo)
{
InventoryComponent->AttachToCharacter(Pickup, StorageInfo.StorageName);
}