diff --git a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset index 473f3f5..a430ecd 100644 Binary files a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset and b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset differ diff --git a/Source/Blaster/Character/BlasterAnimInstance.cpp b/Source/Blaster/Character/BlasterAnimInstance.cpp index 75e02cc..6f047e5 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.cpp +++ b/Source/Blaster/Character/BlasterAnimInstance.cpp @@ -30,5 +30,5 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) bIsInAir = BlasterCharacter->GetCharacterMovement()->IsFalling(); bIsAccelerating = BlasterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0.f; - + bWeaponEquipped = BlasterCharacter->IsWeaponEquipped(); } diff --git a/Source/Blaster/Character/BlasterAnimInstance.h b/Source/Blaster/Character/BlasterAnimInstance.h index eca5894..ba39b87 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.h +++ b/Source/Blaster/Character/BlasterAnimInstance.h @@ -32,4 +32,7 @@ private: UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) bool bIsAccelerating; + + UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) + bool bWeaponEquipped; }; diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index b91f2e6..0472da2 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -144,6 +144,11 @@ void ABlasterCharacter::SetOverlappingWeapon(AWeapon* Weapon) } } +bool ABlasterCharacter::IsWeaponEquipped() +{ + return Combat && Combat->EquippedWeapon; +} + void ABlasterCharacter::OnRep_OverlappingWeapon(AWeapon* LastWeapon) { if (OverlappingWeapon) diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 75beb51..a104766 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -50,4 +50,5 @@ private: void ServerEquipButtonPressed(); public: void SetOverlappingWeapon(AWeapon* Weapon); + bool IsWeaponEquipped(); }; diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 116f160..7070f81 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -6,6 +6,7 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Weapon/Weapon.h" #include "Engine/SkeletalMeshSocket.h" +#include "Net/UnrealNetwork.h" UCombatComponent::UCombatComponent() { @@ -23,6 +24,13 @@ void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo } +void UCombatComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const +{ + Super::GetLifetimeReplicatedProps(OutLifetimeProps); + + DOREPLIFETIME(UCombatComponent, EquippedWeapon); +} + void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) { if (Character == nullptr || WeaponToEquip == nullptr) return; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 6b3f9cd..1cb5281 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -14,9 +14,11 @@ class BLASTER_API UCombatComponent : public UActorComponent public: UCombatComponent(); - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; friend class ABlasterCharacter; - + + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; + void EquipWeapon(class AWeapon* WeaponToEquip); protected: @@ -24,5 +26,7 @@ protected: private: class ABlasterCharacter* Character; + + UPROPERTY(Replicated) class AWeapon* EquippedWeapon; };