// Copyright Epic Games, Inc. All Rights Reserved. #include "LyraEquipmentInstance.h" #include "LyraEquipmentDefinition.h" #include "GameFramework/Character.h" #include "Components/SkeletalMeshComponent.h" #include "Net/UnrealNetwork.h" ULyraEquipmentInstance::ULyraEquipmentInstance(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { } UWorld* ULyraEquipmentInstance::GetWorld() const { if (APawn* OwningPawn = GetPawn()) { return OwningPawn->GetWorld(); } else { return nullptr; } } void ULyraEquipmentInstance::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(ThisClass, Instigator); DOREPLIFETIME(ThisClass, SpawnedActors); } APawn* ULyraEquipmentInstance::GetPawn() const { return Cast(GetOuter()); } APawn* ULyraEquipmentInstance::GetTypedPawn(TSubclassOf PawnType) const { APawn* Result = nullptr; if (UClass* ActualPawnType = PawnType) { if (GetOuter()->IsA(ActualPawnType)) { Result = Cast(GetOuter()); } } return Result; } void ULyraEquipmentInstance::SpawnEquipmentActors(const TArray& ActorsToSpawn) { if (APawn* OwningPawn = GetPawn()) { USceneComponent* AttachTarget = OwningPawn->GetRootComponent(); if (ACharacter* Char = Cast(OwningPawn)) { AttachTarget = Char->GetMesh(); } for (const FLyraEquipmentActorToSpawn& SpawnInfo : ActorsToSpawn) { AActor* NewActor = GetWorld()->SpawnActorDeferred(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); } } } void ULyraEquipmentInstance::DestroyEquipmentActors() { for (AActor* Actor : SpawnedActors) { if (Actor) { Actor->Destroy(); } } } void ULyraEquipmentInstance::OnEquipped() { K2_OnEquipped(); } void ULyraEquipmentInstance::OnUnequipped() { K2_OnUnequipped(); } void ULyraEquipmentInstance::OnRep_Instigator() { }