GAME DEV MASTERCLASS

Launching Grenades in Unreal with Gameplay Ability System: Part 1

An easily-digestible GAS tutorial

The end result we will be able to see very soon.

Getting Started

using UnrealBuildTool;public class SimpleGAS : ModuleRules
{
public SimpleGAS(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "GameplayAbilities", "GameplayTags", "GameplayTasks", "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
}
}
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
/** Gameplay Ability Component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Abilities, meta = (AllowPrivateAccess = "true"))
class UAbilitySystemComponent* AbilitySystemComponent;
public:
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
/** Returns FollowCamera subobject **/
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
/** Returns Ability System Component subobject **/
FORCEINLINE UAbilitySystemComponent* GetAbilitySystemComponent() const override { return AbilitySystemComponent; }
public:
ASimpleGASCharacter();
/** Startup Ability to Grant on BeginPlay */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Abilities)
TSubclassOf<class UGameplayAbility> StartupAbility;
void ASimpleGASCharacter::BeginPlay()
{
Super::BeginPlay();
if ( AbilitySystemComponent && HasAuthority() )
{
if ( StartupAbility )
{
AbilitySystemComponent->GiveAbility( FGameplayAbilitySpec(StartupAbility.GetDefaultObject(), 1, 0) );
AbilitySystemComponent->InitAbilityActorInfo( this, this );
}
}
}
protected:	void BeginPlay() override;	void PossessedBy(AController* NewController) override;	/** Resets HMD orientation in VR. */
void OnResetVR();
void ASimpleGASCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
AbilitySystemComponent->RefreshAbilityActorInfo();
}

Cutting a Corner

Launch Grenade Ability

Ability content setup

Content/ParagonWraith/Characters/Heroes/Wraith/Animations/Ability_Q_Fire_Montage.uasset
The resulting Gameplay Ability Graph of GA_ThrowGrenade ability

Grenade Actor

BP_Greanade/LaunchInDirection function graph.

Result and Key Takeaways

Technical Designer at Yager Interactive. Ex live-producer at Electronic Arts. I write about Unreal Engine development, game business, and technology.