Skip to content

Commit

Permalink
4. Unreal Engine 5 C++ | Gameplay Ability System - Step by Step
Browse files Browse the repository at this point in the history
  • Loading branch information
kaijurgeit committed Apr 12, 2024
1 parent 0d044df commit d3652b5
Show file tree
Hide file tree
Showing 41 changed files with 544 additions and 34 deletions.
3 changes: 2 additions & 1 deletion Config/DefaultGame.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=03BD53194974379BBE6A46A88F4200BC
CopyrightNotice=Fab by Kai Jurgeit

[/Script/GameplayAbilities.AbilitySystemGlobals]
bUseDebugTargetFromHud=true
17 changes: 17 additions & 0 deletions Config/DefaultGameplayTags.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[/Script/GameplayTags.GameplayTagsSettings]
ImportTagsFromConfig=True
WarnOnInvalidTags=True
ClearInvalidTags=False
AllowEditorTagUnloading=True
AllowGameTagUnloading=False
FastReplication=False
InvalidTagCharacters="\"\',"
NumBitsForContainerSize=6
NetIndexFirstBitSegment=16
+GameplayTagList=(Tag="Event.Montage.Kick",DevComment="")
+GameplayTagList=(Tag="Gameplay.Ability.Kick",DevComment="")
+GameplayTagList=(Tag="Gameplay.Cooldown.Kick",DevComment="")
+GameplayTagList=(Tag="Gameplay.Magnitude.Duration",DevComment="")
+GameplayTagList=(Tag="Gameplay.State.IsKicking",DevComment="")
+GameplayTagList=(Tag="GameplayCue.Kick",DevComment="")
4 changes: 2 additions & 2 deletions Content/Fab/Characters/Mannequins/Animations/ABP_Manny.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/Fab/Characters/Mannequins/Meshes/SK_Mannequin.uasset
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Fab/Characters/Player/Abilities/Kick/AM_Kick.uasset
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Fab/Characters/Player/Abilities/Kick/AS_Kick.uasset
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Fab/Characters/Player/Abilities/Kick/GA_Kick.uasset
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Fab/Characters/Player/Abilities/Kick/GE_Kick.uasset
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/Fab/Characters/Player/BP_PlayerCharacter.uasset
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/Fab/Game/BP_FabGameMode.uasset
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Fab/Player/BP_FabPlayerState.uasset
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Fab/UI/BP_FabHUD.uasset
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Fab/UI/WBP_Attributes.uasset
Git LFS file not shown
4 changes: 4 additions & 0 deletions Fab.uproject
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"TargetAllowList": [
"Editor"
]
},
{
"Name": "GameplayAbilities",
"Enabled": true
}
]
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Fab is a co-op third-person RPG which aims at teaching gameplay programming, bei


## Links to each Video and Commit
#### 4. Unreal Engine 5 C++ | Gameplay Ability System - Step by Step
[Video](https://youtu.be/L-3ifQRpyB4) | [main](https://github.com/kaijurgeit/UnrealEngine5CppTutorials/commit/main)

#### 3. Unreal Engine 5 C++ | Git (LFS) and GitHub - Command Line and Rider
[Video](https://youtu.be/jcAwTc_QyWc) | [main](https://github.com/kaijurgeit/UnrealEngine5CppTutorials/commit/main)
[Video](https://youtu.be/jcAwTc_QyWc) | [0d044df](https://github.com/kaijurgeit/UnrealEngine5CppTutorials/commit/0d044df3e8b52e4d5f073543c5884d95e1a4ae68)

#### 2. Unreal Engine 5 C++ | Coding and Debugging with Rider
[Video](https://youtu.be/IT9ihIc9KyI) | [4c61ae8](https://github.com/kaijurgeit/UnrealEngine5CppTutorials/commit/4c61ae89e4b4c2c0ef8a221ed774dee8fef20416)
Expand Down
18 changes: 18 additions & 0 deletions Source/Fab/AbilitySystem/FabAbilitySystemComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Fab by Kai Jurgeit


#include "FabAbilitySystemComponent.h"


UFabAbilitySystemComponent::UFabAbilitySystemComponent()
{
PrimaryComponentTick.bCanEverTick = true;
SetIsReplicated(true);
}

void UFabAbilitySystemComponent::BeginPlay()
{
Super::BeginPlay();

}

20 changes: 20 additions & 0 deletions Source/Fab/AbilitySystem/FabAbilitySystemComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Fab by Kai Jurgeit

#pragma once

#include "CoreMinimal.h"
#include "AbilitySystemComponent.h"
#include "FabAbilitySystemComponent.generated.h"


UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class FAB_API UFabAbilitySystemComponent : public UAbilitySystemComponent
{
GENERATED_BODY()

public:
UFabAbilitySystemComponent();

protected:
virtual void BeginPlay() override;
};
74 changes: 74 additions & 0 deletions Source/Fab/AbilitySystem/FabAttributeSet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Fab by Kai Jurgeit


#include "FabAttributeSet.h"
#include "AbilitySystemComponent.h"
#include "GameplayEffectExtension.h"
#include "Net/UnrealNetwork.h"

UFabAttributeSet::UFabAttributeSet()
{
InitHealth(80.f);
}

void UFabAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);

DOREPLIFETIME_CONDITION_NOTIFY(UFabAttributeSet, Health, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UFabAttributeSet, MaxHealth, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UFabAttributeSet, Stamina, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UFabAttributeSet, MaxStamina, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UFabAttributeSet, Strength, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UFabAttributeSet, MaxStrength, COND_None, REPNOTIFY_Always);
}

void UFabAttributeSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);

if(Attribute == GetHealthAttribute())
{
NewValue = FMath::Clamp(NewValue, 0.f, GetMaxHealth());
}
}

void UFabAttributeSet::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);

if(Data.EvaluatedData.Attribute == GetHealthAttribute())
{
SetHealth(FMath::Clamp(GetHealth(), 0.f, GetMaxHealth()));
}
}

void UFabAttributeSet::OnRep_Health(const FGameplayAttributeData& OldHealth) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UFabAttributeSet, Health, OldHealth);
}

void UFabAttributeSet::OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UFabAttributeSet, MaxHealth, OldMaxHealth);
}

void UFabAttributeSet::OnRep_Stamina(const FGameplayAttributeData& OldStamina) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UFabAttributeSet, Stamina, OldStamina);
}

void UFabAttributeSet::OnRep_MaxStamina(const FGameplayAttributeData& OldMaxStamina) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UFabAttributeSet, MaxStamina, OldMaxStamina);
}

void UFabAttributeSet::OnRep_Strength(const FGameplayAttributeData& OldStrength) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UFabAttributeSet, Strength, OldStrength);
}

void UFabAttributeSet::OnRep_MaxStrength(const FGameplayAttributeData& OldMaxStrength) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UFabAttributeSet, MaxStrength, OldMaxStrength);
}
73 changes: 73 additions & 0 deletions Source/Fab/AbilitySystem/FabAttributeSet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Fab by Kai Jurgeit

#pragma once

#include "CoreMinimal.h"
#include "AbilitySystemComponent.h"
#include "AttributeSet.h"
#include "FabAttributeSet.generated.h"

#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)

#define NUMERIC_VALUE(AttributeSetName, PropertyName) \
AttributeSetName->Get##PropertyName##Attribute().GetNumericValue(AttributeSetName)

/**
*
*/
UCLASS()
class FAB_API UFabAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UFabAttributeSet();
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;

UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Health, Category = "Ability | Gameplay Attribute")
FGameplayAttributeData Health;
ATTRIBUTE_ACCESSORS(UFabAttributeSet, Health);

UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxHealth, Category = "Ability | Gameplay Attribute")
FGameplayAttributeData MaxHealth;
ATTRIBUTE_ACCESSORS(UFabAttributeSet, MaxHealth);

UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Stamina, Category = "Ability | Gameplay Attribute")
FGameplayAttributeData Stamina;
ATTRIBUTE_ACCESSORS(UFabAttributeSet, Stamina);

UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxStamina, Category = "Ability | Gameplay Attribute")
FGameplayAttributeData MaxStamina;
ATTRIBUTE_ACCESSORS(UFabAttributeSet, MaxStamina);

UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Strength, Category = "Ability | Gameplay Attribute")
FGameplayAttributeData Strength;
ATTRIBUTE_ACCESSORS(UFabAttributeSet, Strength);

UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxStrength, Category = "Ability | Gameplay Attribute")
FGameplayAttributeData MaxStrength;
ATTRIBUTE_ACCESSORS(UFabAttributeSet, MaxStrength);

UFUNCTION()
void OnRep_Health(const FGameplayAttributeData& OldHealth) const;

UFUNCTION()
void OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth) const;

UFUNCTION()
void OnRep_Stamina(const FGameplayAttributeData& OldStamina) const;

UFUNCTION()
void OnRep_MaxStamina(const FGameplayAttributeData& OldMaxStamina) const;

UFUNCTION()
void OnRep_Strength(const FGameplayAttributeData& OldStamina) const;

UFUNCTION()
void OnRep_MaxStrength(const FGameplayAttributeData& OldMaxStamina) const;
};
10 changes: 9 additions & 1 deletion Source/Fab/Characters/EnemyCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@


#include "EnemyCharacter.h"
#include "AbilitySystem/FabAbilitySystemComponent.h"
#include "AbilitySystem/FabAttributeSet.h"


AEnemyCharacter::AEnemyCharacter()
{
PrimaryActorTick.bCanEverTick = true;

AbilitySystemComponent = CreateDefaultSubobject<UFabAbilitySystemComponent>("AbilitySystemComponent");
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);
AttributeSet = CreateDefaultSubobject<UFabAttributeSet>("AttributeSet");
}

void AEnemyCharacter::BeginPlay()
{
Super::BeginPlay();

AbilitySystemComponent->InitAbilityActorInfo(this, this);
GiveDefaultAbilities();
InitDefaultAttributes();
}

Loading

0 comments on commit d3652b5

Please sign in to comment.