GKLPlayerState.h
Click a line number to link it. Shift-click to select a range.
| 1 | // Copyright (c) 2026 Reignance Studios. MIT License, see LICENSE. |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include "CoreMinimal.h" |
| 6 | #include "AbilitySystemInterface.h" |
| 7 | #include "GameFramework/PlayerState.h" |
| 8 | #include "GKLPlayerState.generated.h" |
| 9 | |
| 10 | class UAbilitySystemComponent; |
| 11 | class UGameplayAbility; |
| 12 | class UGKLAttributeSet; |
| 13 | |
| 14 | /** |
| 15 | * Owns the Ability System Component and the AttributeSet, so abilities, effects and |
| 16 | * attributes survive the pawn dying and respawning. |
| 17 | * |
| 18 | * - ASC replicates in Mixed mode: the owning client gets its own effects (needed for |
| 19 | * predicted cost and cooldown), other clients only get tags and cues. |
| 20 | * - Net update frequency 100: ability confirmations ride on this actor. |
| 21 | * - StartupAbilities are granted once, on the server, in BeginPlay. |
| 22 | */ |
| 23 | UCLASS() |
| 24 | class GASKITLITE_API AGKLPlayerState : public APlayerState, public IAbilitySystemInterface |
| 25 | { |
| 26 | GENERATED_BODY() |
| 27 | |
| 28 | public: |
| 29 | AGKLPlayerState(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get()); |
| 30 | |
| 31 | virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override; |
| 32 | |
| 33 | UFUNCTION(BlueprintPure, Category = "GASKit Lite") |
| 34 | UGKLAttributeSet* GetAttributeSet() const { return AttributeSet; } |
| 35 | |
| 36 | /** Server only. Clears State.Dead, refills attributes and restarts passive abilities. Call before possessing a new pawn. */ |
| 37 | UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category = "GASKit Lite") |
| 38 | void ResetForRespawn(); |
| 39 | |
| 40 | protected: |
| 41 | virtual void BeginPlay() override; |
| 42 | |
| 43 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "GASKit Lite") |
| 44 | TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent; |
| 45 | |
| 46 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "GASKit Lite") |
| 47 | TObjectPtr<UGKLAttributeSet> AttributeSet; |
| 48 | |
| 49 | /** Granted on the server in BeginPlay. Defaults to the five sample abilities. */ |
| 50 | UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "GASKit Lite") |
| 51 | TArray<TSubclassOf<UGameplayAbility>> StartupAbilities; |
| 52 | |
| 53 | private: |
| 54 | bool bStartupAbilitiesGranted = false; |
| 55 | }; |