What I’m trying to do:
i’m trying to use IK retargeting to use Lyra’s template animations with custom made character made in Blender, which has a shorter and wider skeleton.
The problem:
The IK retarget is working but the weapon is spawned in the socket of the Manny/Quinn Invis rather than in the weapon_r socket of the retarget-destination skmesh.
My possible idea:
Add some code in the ULyraEquipmentInstance::SpawnEquipmentActors to first look for SceneComponent attachments that can cast to ALyraTaggedActor, and only if not possible then attach to the rootcomponent of the pawn.
void ULyraEquipmentInstance::SpawnEquipmentActors(const TArray<FLyraEquipmentActorToSpawn>& ActorsToSpawn)
{
if (APawn* OwningPawn = GetPawn())
{
TArray<USceneComponent*> AttachedChildren;
OwningPawn->GetRootComponent()->GetChildrenComponents(true, AttachedChildren);
bool found = false;
for (USceneComponent* Child : AttachedChildren)
{
if (Child)
{
AActor* actor = Child->GetAttachParentActor();
if (ALyraTaggedActor* Char = Cast<ALyraTaggedActor>(actor))
{
USkeletalMeshComponent* SubAttachTarget = Char->FindComponentByClass<USkeletalMeshComponent>();
if (!SubAttachTarget)
{
UE_LOG(LogTemp, Log, TEXT("Skeletral Mesh not found in ALyraTaggedActor: %s"), *Char->GetName());
continue;
}
for (const FLyraEquipmentActorToSpawn& SpawnInfo : ActorsToSpawn)
{
AActor* NewActor = GetWorld()->SpawnActorDeferred<AActor>(SpawnInfo.ActorToSpawn, FTransform::Identity, Char);
NewActor->FinishSpawning(FTransform::Identity, /*bIsDefaultTransform=*/ true);
NewActor->SetActorRelativeTransform(SpawnInfo.AttachTransform);
NewActor->AttachToComponent(SubAttachTarget, FAttachmentTransformRules::KeepRelativeTransform, SpawnInfo.AttachSocket);
SpawnedActors.Add(NewActor);
}
found = true;
}
}
if (found)
return;
}
USceneComponent* AttachTarget = OwningPawn->GetRootComponent();
if (ACharacter* Char = Cast<ACharacter>(OwningPawn))
{
AttachTarget = Char->GetMesh();
}
for (const FLyraEquipmentActorToSpawn& SpawnInfo : ActorsToSpawn)
{
AActor* NewActor = GetWorld()->SpawnActorDeferred<AActor>(SpawnInfo.ActorToSpawn, FTransform::Identity, OwningPawn);
NewActor->FinishSpawning(FTransform::Identity, /*bIsDefaultTransform=*/ true);
NewActor->SetActorRelativeTransform(SpawnInfo.AttachTransform);
NewActor->AttachToComponent(AttachTarget, FAttachmentTransformRules::KeepRelativeTransform, SpawnInfo.AttachSocket);
SpawnedActors.Add(NewActor);
}
}
}
Unfortunately if i do so, the spawn is not correctly replicated and in the client the spawned weapon is orphaned in the scene rather than parented to the actor as happens on the server (and in both client and server without my added code).