Gameplay Ability System - Unable to apply initial effects and give initial abilities when actors spawn.

I am having this issue where the characters I possess in the world when they spawn, are not having their initial effects or abilities applied and given.

At the moment I am making my characters run into a volume of effect, when every character is possessed, that calls the relevant initalize method to initialize the effects and abilities.

I am referring tranek’s GASDocumentation repo and implementing GAS for my project. I am trying to initialize the AbilitySystem in the player controller.

I have the following hierarchy for my characters in the game:

base_char
 - Hero
    - BP_Hero
 - non_hero
    - BP_non_hero

The above characters are written in C++.

I have a blueprint class sub-classed from hero - BP_hero, which is what is being used in the world. non_hero is something like a mob or minion in the world.

This is what my base_char looks like.


Abase_char::Abase_char()
{
 	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	NetUpdateFrequency = 100.f;
		
	ABILITY_SYSTEM_COMPONENT =
		CreateDefaultSubobject<UABILITY_SYSTEM_COMPONENT>("ABILITY_SYSTEM_COMPONENT");
	ABILITY_SYSTEM_COMPONENT->SetIsReplicated(true);

	CONSTITUTION_attribute_set = CreateDefaultSubobject<UCONSTITUTION_attribute_set>("CONSTITUTION_attribute_set");
	
	ARCANE_attribute_set = CreateDefaultSubobject<UARCANE_attribute_set>("ARCANE_attribute_set");
	
	// ...
}

// Happens only in the server
void Abase_char::PossessedBy(AController* NewController)
{
	Super::PossessedBy(NewController);

	SetOwner(NewController);

	ABILITY_SYSTEM_COMPONENT->InitAbilityActorInfo(this, this);

	// This is where all initial
	// effects and abilities are applied
	ABILITY_SYSTEM_COMPONENT->initialize_ASC();

}


This is my controller class:


Abase_player_controller::Abase_player_controller()
{
	bReplicates = true;
}

// Happens only in the client
void Abase_player_controller::AcknowledgePossession(APawn* P)
{
	Super::AcknowledgePossession(P);

	base_char_ = Cast<Abase_char>(GetPawn());

	if (!base_char_) return;

	ASC_ = Cast<UABILITY_SYSTEM_COMPONENT>(
		base_char_->GetAbilitySystemComponent()
	);

	if (!ASC_) return;

	ASC_->InitAbilityActorInfo(base_char_, base_char_);
	
}


Where base_char_ and ASC_ are references being stored in Abase_player_controller class.

I have also sub-classed from the UAbilitySystemComponent class and made my own UABILITY_SYSTEM_COMPONENT class for extended functionalities that I can do with my actors.

This is the implementation of that class:


void UABILITY_SYSTEM_COMPONENT::initialize_ASC()
{
	base_char_ = Cast<Abase_char>(GetAvatarActor());

	if (GetOwnerRole() != ROLE_Authority) return;

	initialize_abilities();

	initial_effects();

}

void UABILITY_SYSTEM_COMPONENT::initialize_abilities()
{
	if (!base_char_) return;

	for (const auto & pair_ : base_char_->ability_input_container)
	{
		FGameplayAbilitySpec ability_spec_ = FGameplayAbilitySpec(pair_.Value.ability_class, 1);

		GiveAbility(ability_spec_);
	}

	b_initial_abilities_provided = true;
}

void UABILITY_SYSTEM_COMPONENT::initial_effects()
{
	if (!base_char_) return;

	for (const auto & effect_class_ : base_char_->initial_effect_container)
	{
		FGameplayEffectContextHandle current_effect_context_handle_;
		current_effect_context_handle_.AddSourceObject(this);

		FGameplayEffectSpecHandle current_effect_spec_handle_ = MakeOutgoingSpec(
			 effect_class_,
			 base_char_->level,
			 current_effect_context_handle_
		);

		ApplyGameplayEffectSpecToSelf(
			*current_effect_spec_handle_.Data.Get(),
			FPredictionKey()
		);

	}

	b_initial_effects_applied = true;
}

Furthermore, I have defined the Replication mode in the hero and non_hero classes like this:

hero


AHERO::AHERO()
{

	// Mixed
	
	ABILITY_SYSTEM_COMPONENT->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);

}

non_hero


ANON_HERO::ANON_HERO()
{
	// Minimal 

	ABILITY_SYSTEM_COMPONENT->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);
}


But still, no matter how hard I try, I am not getting the actor to initialize ASC.

I need this to work because my project involves creating clones (like kage no bunshin from naruto, or Phantom Lancer from DOTA 2).

The clones are being spawned in the server, but when I call initialize_ASC method to initialize them, (whether server or net-multicast, local or non-replicated) their ASC just refuses to have their effects applied!!

How to initialize the ASC as soon as the character spawns in the world?
Where am I going wrong?

Please help.

PS:

Also, do you suggest I use my own ability system?
Because I have built my own for multiplayer in C++ and it is very extensive.
I am very happy with how I can build a lot in a short span of time.

Please let me know.

Thanks in advance.