I use slightly modified lyra “equipment actors” spawned by “equipment instance” logic (the thing I addes is that instance can be visible right now or not and it changes spawned actors visibility and linked animation layer. Eg you can have two handed ranged weapon equiped along with a sword, but only 1 item is visible at 1 time).
void UECREquipmentInstance::SpawnEquipmentActors(const TArray<FECREquipmentActorToSpawn>& ActorsToSpawn)
{
if (APawn* OwningPawn = GetPawn())
{
USceneComponent* AttachTarget = OwningPawn->GetRootComponent();
if (ACharacter* Char = Cast<ACharacter>(OwningPawn))
{
AttachTarget = Char->GetMesh();
}
const UECRPawnComponent_CharacterParts* CosmeticComponent = OwningPawn->FindComponentByClass<
UECRPawnComponent_CharacterParts>();
FGameplayTagContainer CosmeticTags = {};
if (CosmeticComponent)
{
CosmeticTags = CosmeticComponent->GetCombinedTags(FECRGameplayTags::Get().Cosmetic_ActorSubclass);
}
for (const FECREquipmentActorToSpawn& SpawnInfo : ActorsToSpawn)
{
TSubclassOf<AActor> ActorClass = SpawnInfo.ActorSelectionSet.SelectBestActor(CosmeticTags);
AActor* NewActor = GetWorld()->SpawnActorDeferred<AActor>(ActorClass, FTransform::Identity,
OwningPawn);
NewActor->FinishSpawning(FTransform::Identity, /*bIsDefaultTransform=*/ true);
NewActor->SetActorRelativeTransform(SpawnInfo.AttachTransform);
NewActor->AttachToComponent(AttachTarget, FAttachmentTransformRules::KeepRelativeTransform,
SpawnInfo.AttachSocket);
NewActor->SetActorHiddenInGame(!bVisible);
if (!NewActor->GetIsReplicated())
{
NewActor->SetReplicates(true);
}
SpawnedActors.Add(NewActor);
}
}
}
However, the problem is that weapons are visible when replay is recorded by listen server, but not visible when replay is recorded by client. Though, some actors like grenades are visible.