From e97ed90ffd0951197a827e1a1d37e3e49e818fc2 Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 10 May 2024 18:03:22 +0100 Subject: [PATCH] Replace SkeletalMesh with SkeletalMeshComponent --- Source/Nakatomi/NakatomiCharacter.cpp | 1 + Source/Nakatomi/RandomWeapon.cpp | 2 +- Source/Nakatomi/Weapon.cpp | 13 ++++++++++--- Source/Nakatomi/Weapon.h | 5 +++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index 6a43ab0..df9c92e 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -188,6 +188,7 @@ AWeapon* ANakatomiCharacter::InitializeWeapon(TSubclassOf weapon) FActorSpawnParameters SpawnParameters; SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; AWeapon* Weapon = GetWorld()->SpawnActor(weapon, SpawnParameters); + Weapon->SetOwner(this); Weapon->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, "WeaponHand"); Weapon->SetActorEnableCollision(false); Weapon->SetActorHiddenInGame(true); diff --git a/Source/Nakatomi/RandomWeapon.cpp b/Source/Nakatomi/RandomWeapon.cpp index bd0269c..4753730 100644 --- a/Source/Nakatomi/RandomWeapon.cpp +++ b/Source/Nakatomi/RandomWeapon.cpp @@ -11,7 +11,7 @@ ARandomWeapon::ARandomWeapon() void ARandomWeapon::BeginPlay() { WeaponProperties = RandomWeaponParameters->GenerateRandomWeaponProperties(); - WeaponSkeletalMesh = RandomWeaponParameters->PickRandomMesh(); + WeaponSkeletalMeshComponent->SetSkeletalMeshAsset(RandomWeaponParameters->PickRandomMesh()); FireSound = RandomWeaponParameters->PickRandomSoundBase(); FieldSystemActor = RandomWeaponParameters->PickRandomFieldSystem(); diff --git a/Source/Nakatomi/Weapon.cpp b/Source/Nakatomi/Weapon.cpp index 4f5adfe..c5a0309 100644 --- a/Source/Nakatomi/Weapon.cpp +++ b/Source/Nakatomi/Weapon.cpp @@ -6,7 +6,14 @@ // Sets default values AWeapon::AWeapon() -{ +{ + WeaponSkeletalMeshComponent = CreateDefaultSubobject(TEXT("Skeletal Mesh Component")); + WeaponSkeletalMeshComponent->SetCollisionProfileName(FName("NoCollision")); + WeaponSkeletalMeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision); + WeaponSkeletalMeshComponent->SetSimulatePhysics(false); + WeaponSkeletalMeshComponent->SetGenerateOverlapEvents(false); + WeaponSkeletalMeshComponent->SetNotifyRigidBodyCollision(false); + SetRootComponent(WeaponSkeletalMeshComponent); } // Called when the game starts or when spawned @@ -19,12 +26,12 @@ void AWeapon::BeginPlay() USkeletalMesh* AWeapon::GetSkeletalMesh() { - return WeaponSkeletalMesh; + return WeaponSkeletalMeshComponent->GetSkeletalMeshAsset(); } void AWeapon::SetSkeletalMesh(USkeletalMesh* USkeletalMesh) { - WeaponSkeletalMesh = USkeletalMesh; + WeaponSkeletalMeshComponent->SetSkeletalMeshAsset(USkeletalMesh); } TEnumAsByte* AWeapon::GetCurrentWeaponStatus() diff --git a/Source/Nakatomi/Weapon.h b/Source/Nakatomi/Weapon.h index 2033f41..9301f15 100644 --- a/Source/Nakatomi/Weapon.h +++ b/Source/Nakatomi/Weapon.h @@ -29,8 +29,8 @@ class NAKATOMI_API AWeapon : public AActor GENERATED_BODY() protected: - UPROPERTY(EditDefaultsOnly) - USkeletalMesh* WeaponSkeletalMesh = nullptr; + UPROPERTY(BlueprintReadWrite) + USkeletalMeshComponent* WeaponSkeletalMeshComponent; UPROPERTY(EditDefaultsOnly) TEnumAsByte CurrentWeaponStatus; @@ -65,6 +65,7 @@ public: protected: // Called when the game starts or when spawned + UFUNCTION(Blueprintable, BlueprintCallable) virtual void BeginPlay() override; public: