diff --git a/EndlessVendetta/Source/EndlessVendetta/MyVICharacterAbilityBase.cpp b/EndlessVendetta/Source/EndlessVendetta/MyVICharacterAbilityBase.cpp new file mode 100644 index 00000000..40972d0c --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/MyVICharacterAbilityBase.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2019-2022 Drowning Dragons Limited. All Rights Reserved. + +#include "MyVICharacterAbilityBase.h" + +////#include "Pawn/VICharacterAbilityBase.h" +#include "GAS/VIAbilitySystemComponent.h" + +AMyVICharacterAbilityBase::AMyVICharacterAbilityBase(const FObjectInitializer& OI) + : Super(OI) +{ + AbilitySystem = CreateDefaultSubobject(TEXT("AbilitySystem")); + AbilitySystem->SetIsReplicated(true); + AbilitySystem->SetReplicationMode(EGameplayEffectReplicationMode::Mixed); + AbilitySystemReplicationMode = (EVIGameplayEffectReplicationMode)(uint8)AbilitySystem->ReplicationMode; +} + +#if WITH_EDITOR +void AMyVICharacterAbilityBase::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) +{ + Super::PostEditChangeProperty(PropertyChangedEvent); + + if (PropertyChangedEvent.GetPropertyName().IsEqual(GET_MEMBER_NAME_CHECKED(AMyVICharacterAbilityBase, AbilitySystemReplicationMode))) + { + AbilitySystem->SetReplicationMode((EGameplayEffectReplicationMode)(uint8)AbilitySystemReplicationMode); + } +} +#endif // WITH_EDITOR + +UAbilitySystemComponent* AMyVICharacterAbilityBase::GetAbilitySystemComponent() const +{ + return AbilitySystem; +} diff --git a/EndlessVendetta/Source/EndlessVendetta/MyVICharacterAbilityBase.h b/EndlessVendetta/Source/EndlessVendetta/MyVICharacterAbilityBase.h new file mode 100644 index 00000000..391d5320 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/MyVICharacterAbilityBase.h @@ -0,0 +1,54 @@ +// Copyright (c) 2019-2022 Drowning Dragons Limited. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" +#include "Pawn/VICharacterBase.h" +#include "AbilitySystemInterface.h" +#include "MyVICharacterAbilityBase.generated.h" + +class UVIAbilitySystemComponent; + +/** + * Adds a UVIAbilitySystemComponent to your character base + * Allows switching replication mode in Blueprint for the sake of AI using Minimal instead of Mixed + */ +UCLASS() +class ENDLESSVENDETTA_API AMyVICharacterAbilityBase : public AVICharacterBase, public IAbilitySystemInterface +{ + GENERATED_BODY() + +public: + UPROPERTY(BlueprintReadOnly, Category = Abilities) + UVIAbilitySystemComponent* AbilitySystem; + +protected: + /** + * Used by blueprints to allow changing replication mode which is usually + * only accessible via C++ + * + * Recommended as follows: + * For player characters use Mixed + * For AI characters use Minimal + */ + UPROPERTY(EditDefaultsOnly, Category = Abilities) + EVIGameplayEffectReplicationMode AbilitySystemReplicationMode; + +public: + AMyVICharacterAbilityBase(const FObjectInitializer& OI); + +#if WITH_EDITOR + virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override; +#endif // WITH_EDITOR + +protected: + // *********************************************** // + // ******** Begin IAbilitySystemInterface ******** // + // *********************************************** // + + virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override; + + // *********************************************** // + // ********* End IAbilitySystemInterface ********* // + // *********************************************** // +}; \ No newline at end of file