// Copyright (c) 2026 Reignance Studios. MIT License, see LICENSE. #include "GKLCharacter.h" #include "AbilitySystemComponent.h" #include "GameFramework/CharacterMovementComponent.h" #include "GKLPlayerState.h" #include "Net/UnrealNetwork.h" AGKLCharacter::AGKLCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { bReplicates = true; SetReplicateMovement(true); } void AGKLCharacter::PossessedBy(AController* NewController) { Super::PossessedBy(NewController); InitAbilitySystem(); // server } void AGKLCharacter::OnRep_PlayerState() { Super::OnRep_PlayerState(); InitAbilitySystem(); // owning client (and simulated proxies, which is harmless) } void AGKLCharacter::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(AGKLCharacter, bIsDead); } UAbilitySystemComponent* AGKLCharacter::GetAbilitySystemComponent() const { const AGKLPlayerState* PS = GetPlayerState(); return PS ? PS->GetAbilitySystemComponent() : nullptr; } void AGKLCharacter::InitAbilitySystem() { AGKLPlayerState* PS = GetPlayerState(); if (UAbilitySystemComponent* ASC = PS ? PS->GetAbilitySystemComponent() : nullptr) { // Owner = PlayerState (survives respawn), avatar = this pawn (what abilities act on). ASC->InitAbilityActorInfo(PS, this); } } bool AGKLCharacter::ActivateAbilityByTag(FGameplayTag AbilityTag) { UAbilitySystemComponent* ASC = GetAbilitySystemComponent(); return ASC && AbilityTag.IsValid() && ASC->TryActivateAbilitiesByTag(FGameplayTagContainer(AbilityTag)); } void AGKLCharacter::Die() { if (!HasAuthority() || bIsDead) { return; } bIsDead = true; OnDeath(); } void AGKLCharacter::OnRep_IsDead() { if (bIsDead) { OnDeath(); } } void AGKLCharacter::OnDeath_Implementation() { GetCharacterMovement()->DisableMovement(); }