Skip to content

Ability Set - Swap giving effects and giving attribute set order #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Source/GameBaseFramework/Private/GAS/Abilities/GBFAbilitySet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,43 +112,43 @@ void UGBFAbilitySet::GiveToAbilitySystem( UAbilitySystemComponent * asc, FGBFAbi
}
}

// Grant the gameplay effects.
for ( auto effect_index = 0; effect_index < GrantedGameplayEffects.Num(); ++effect_index )
// Grant the attribute sets.
for ( auto set_index = 0; set_index < GrantedAttributes.Num(); ++set_index )
{
const auto & effect_to_grant = GrantedGameplayEffects[ effect_index ];
const auto & set_to_grant = GrantedAttributes[ set_index ];

if ( !IsValid( effect_to_grant.GameplayEffect ) )
if ( !IsValid( set_to_grant.AttributeSet ) )
{
UE_LOG( LogGBF_GAS, Error, TEXT( "GrantedGameplayEffects[%d] on ability set [%s] is not valid" ), effect_index, *GetNameSafe( this ) );
UE_LOG( LogGBF_GAS, Error, TEXT( "GrantedAttributes[%d] on ability set [%s] is not valid" ), set_index, *GetNameSafe( this ) );
continue;
}

const auto * gameplay_effect = effect_to_grant.GameplayEffect->GetDefaultObject< UGameplayEffect >();
const auto gameplay_effect_handle = asc->ApplyGameplayEffectToSelf( gameplay_effect, effect_to_grant.EffectLevel, asc->MakeEffectContext() );
auto * new_set = NewObject< UAttributeSet >( asc->GetOwner(), set_to_grant.AttributeSet );
asc->AddAttributeSetSubobject( new_set );

if ( out_granted_handles != nullptr )
{
out_granted_handles->AddGameplayEffectHandle( gameplay_effect_handle );
out_granted_handles->AddAttributeSet( new_set );
}
}

// Grant the attribute sets.
for ( auto set_index = 0; set_index < GrantedAttributes.Num(); ++set_index )
// Grant the gameplay effects.
for ( auto effect_index = 0; effect_index < GrantedGameplayEffects.Num(); ++effect_index )
{
const auto & set_to_grant = GrantedAttributes[ set_index ];
const auto & effect_to_grant = GrantedGameplayEffects[ effect_index ];

if ( !IsValid( set_to_grant.AttributeSet ) )
if ( !IsValid( effect_to_grant.GameplayEffect ) )
{
UE_LOG( LogGBF_GAS, Error, TEXT( "GrantedAttributes[%d] on ability set [%s] is not valid" ), set_index, *GetNameSafe( this ) );
UE_LOG( LogGBF_GAS, Error, TEXT( "GrantedGameplayEffects[%d] on ability set [%s] is not valid" ), effect_index, *GetNameSafe( this ) );
continue;
}

auto * new_set = NewObject< UAttributeSet >( asc->GetOwner(), set_to_grant.AttributeSet );
asc->AddAttributeSetSubobject( new_set );
const auto * gameplay_effect = effect_to_grant.GameplayEffect->GetDefaultObject< UGameplayEffect >();
const auto gameplay_effect_handle = asc->ApplyGameplayEffectToSelf( gameplay_effect, effect_to_grant.EffectLevel, asc->MakeEffectContext() );

if ( out_granted_handles != nullptr )
{
out_granted_handles->AddAttributeSet( new_set );
out_granted_handles->AddGameplayEffectHandle( gameplay_effect_handle );
}
}
}
Loading