Re-Worked Workbench code to use sockets instead of mesh loc

This commit is contained in:
MARCEL HARA 2024-01-26 18:35:44 +00:00
parent 57c55fb762
commit e3af853bdd

View File

@ -257,11 +257,18 @@ void ABaseWeaponClass::InteractPrompt()
void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh) void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh)
{ {
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP SILENCER ATTACHMENTS"));
FTransform emptytransform; FTransform emptytransform;
UActorComponent* SilencerComponent = AddComponentByClass(USilencerAttachmentClass::StaticClass(), true, emptytransform, false); UActorComponent* SilencerComponent = AddComponentByClass(USilencerAttachmentClass::StaticClass(), true, emptytransform, false);
Cast<USilencerAttachmentClass>(SilencerComponent)->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetIncludingScale); UStaticMeshComponent* SilencerMeshComponent = Cast<UStaticMeshComponent>(AddComponentByClass(UStaticMeshComponent::StaticClass(), true, emptytransform, false));
TArray<UActorComponent*> SilencerMeshSocketArray (GetComponentsByTag(UStaticMeshComponent::StaticClass(), FName("SilencerMeshSocket"))); SilencerMeshComponent->SetStaticMesh(SilencerMesh);
Cast<UStaticMeshComponent>(SilencerMeshSocketArray[0])->SetStaticMesh(SilencerMesh); SilencerMeshComponent->AttachToComponent(Cast<USceneComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass())), FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("SilencerMeshSocket")));
Cast<USilencerAttachmentClass>(SilencerComponent)->AttachToComponent(SilencerMeshComponent, FAttachmentTransformRules::SnapToTargetIncludingScale);
FTransform SilencerSocketTransform = SilencerMeshComponent->GetSocketTransform(FName(TEXT("SilencerMeshSocket")), RTS_Component);
FRotator SilencerSocketRotation = SilencerMeshComponent->GetSocketRotation(FName(TEXT("SilencerMeshSocket")));
SilencerMeshComponent->SetRelativeTransform(SilencerSocketTransform);
SilencerMeshComponent->SetRelativeRotation(this->GetActorRotation());
} }