diff --git a/ModularFeatures_ExtraActions.uplugin b/ModularFeatures_ExtraActions.uplugin index 31331c1..4e845e4 100644 --- a/ModularFeatures_ExtraActions.uplugin +++ b/ModularFeatures_ExtraActions.uplugin @@ -1,7 +1,7 @@ { "FileVersion": 3, - "Version": 2, - "VersionName": "1.2.2", + "Version": 3, + "VersionName": "1.2.3", "FriendlyName": "Modular Features: Extra Actions", "Description": "Integrates GAS and Enhanced Input to the existing Game Features and Modular plugins.", "Category": "Game Features", diff --git a/Source/Private/Actions/GameFeatureAction_AddAbilities.cpp b/Source/Private/Actions/GameFeatureAction_AddAbilities.cpp index 759bdc8..f828563 100644 --- a/Source/Private/Actions/GameFeatureAction_AddAbilities.cpp +++ b/Source/Private/Actions/GameFeatureAction_AddAbilities.cpp @@ -7,9 +7,13 @@ #include #include +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(GameFeatureAction_AddAbilities) +#endif + void UGameFeatureAction_AddAbilities::OnGameFeatureActivating(FGameFeatureActivatingContext& Context) { - if (!ensureAlways(ActiveExtensions.IsEmpty()) || !ensureAlways(ActiveRequests.IsEmpty())) + if (!ensureAlways(ActiveExtensions.IsEmpty())) { ResetExtension(); } @@ -20,7 +24,6 @@ void UGameFeatureAction_AddAbilities::OnGameFeatureActivating(FGameFeatureActiva void UGameFeatureAction_AddAbilities::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) { Super::OnGameFeatureDeactivating(Context); - ResetExtension(); } @@ -32,16 +35,14 @@ void UGameFeatureAction_AddAbilities::ResetExtension() RemoveActorAbilities(ExtensionIterator->Key.Get()); } - ActiveRequests.Empty(); + Super::ResetExtension(); } void UGameFeatureAction_AddAbilities::AddToWorld(const FWorldContext& WorldContext) { - if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); - IsValid(ComponentManager) && !TargetPawnClass.IsNull()) + if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); IsValid(ComponentManager) && !TargetPawnClass.IsNull()) { using FHandlerDelegate = UGameFrameworkComponentManager::FExtensionHandlerDelegate; - const FHandlerDelegate ExtensionHandlerDelegate = FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddAbilities::HandleActorExtension); ActiveRequests.Add(ComponentManager->AddExtensionHandler(TargetPawnClass, ExtensionHandlerDelegate)); @@ -50,8 +51,6 @@ void UGameFeatureAction_AddAbilities::AddToWorld(const FWorldContext& WorldConte void UGameFeatureAction_AddAbilities::HandleActorExtension(AActor* Owner, const FName EventName) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("Event %s sent by Actor %s for ability management."), *EventName.ToString(), *Owner->GetName()); - if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved || EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved) { RemoveActorAbilities(Owner); @@ -74,7 +73,7 @@ void UGameFeatureAction_AddAbilities::HandleActorExtension(AActor* Owner, const { if (Entry.AbilityClass.IsNull()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Ability class is null."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Ability class is null."), *FString(__func__)); } else { @@ -95,7 +94,7 @@ void UGameFeatureAction_AddAbilities::AddActorAbilities(AActor* TargetActor, con return; } - if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor)) + if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentInActor(TargetActor)) { // If InputID Enumeration using is disabled, assume -1 as value const int32 InputID = ModularFeaturesHelper::GetInputIDByName(Ability.InputIDValueName, InputIDEnumeration_Ptr.Get()); @@ -106,14 +105,13 @@ void UGameFeatureAction_AddAbilities::AddActorAbilities(AActor* TargetActor, con // Load the ability class and store into a const variable const TSubclassOf AbilityToAdd = Ability.AbilityClass.LoadSynchronous(); - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Adding ability %s to Actor %s."), *FString(__func__), *AbilityToAdd->GetName(), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Adding ability %s to Actor %s."), *FString(__func__), *AbilityToAdd->GetName(), *TargetActor->GetName()); // Create the spec, used to give the ability to target's ability system component FGameplayAbilitySpec NewAbilitySpec(AbilityToAdd, Ability.AbilityLevel, InputID, TargetActor); // Try to give the ability to the target and check if the spec handle is valid - if (const FGameplayAbilitySpecHandle NewSpecHandle = AbilitySystemComponent->GiveAbility(NewAbilitySpec); - NewSpecHandle.IsValid()) + if (const FGameplayAbilitySpecHandle NewSpecHandle = AbilitySystemComponent->GiveAbility(NewAbilitySpec); NewSpecHandle.IsValid()) { // Add the spec handle to the ability data NewAbilityData.SpecHandle.Add(NewSpecHandle); @@ -125,8 +123,7 @@ void UGameFeatureAction_AddAbilities::AddActorAbilities(AActor* TargetActor, con const IMFEA_AbilityInputBinding* const SetupInputInterface = ModularFeaturesHelper::GetAbilityInputBindingInterface(TargetActor, InputBindingOwnerOverride); // If we can bind the input to the target interface, we must add the input reference to the ability data - if (UInputAction* const AbilityInput = Ability.InputAction.LoadSynchronous(); - ModularFeaturesHelper::BindAbilityInputToInterfaceOwner(SetupInputInterface, AbilityInput, NewAbilitySpec)) + if (UInputAction* const AbilityInput = Ability.InputAction.LoadSynchronous(); ModularFeaturesHelper::BindAbilityInputToInterfaceOwner(SetupInputInterface, AbilityInput, NewAbilitySpec)) { NewAbilityData.InputReference.Add(AbilityInput); } @@ -137,7 +134,7 @@ void UGameFeatureAction_AddAbilities::AddActorAbilities(AActor* TargetActor, con } else { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } } @@ -157,20 +154,21 @@ void UGameFeatureAction_AddAbilities::RemoveActorAbilities(AActor* TargetActor) } // Check if we can remove the abilities from this target actor by checking if it is inside the active extensions map - FActiveAbilityData ActiveAbilities = ActiveExtensions.FindRef(TargetActor); - if constexpr (&ActiveAbilities == nullptr) + FActiveAbilityData* const ActiveAbilities = ActiveExtensions.Find(TargetActor); + if (!ActiveAbilities) { - UE_LOG(LogGameplayFeaturesExtraActions, Warning, TEXT("%s: No active abilities found for Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Warning, TEXT("%s: No active abilities found for Actor %s."), *FString(__func__), *TargetActor->GetName()); ActiveExtensions.Remove(TargetActor); + return; } - if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor)) + if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentInActor(TargetActor)) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Removing associated abilities from Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Removing associated abilities from Actor %s."), *FString(__func__), *TargetActor->GetName()); // Iterate the active abilities and remove all spec handle associated to this actor - for (const FGameplayAbilitySpecHandle& SpecHandle : ActiveAbilities.SpecHandle) + for (const FGameplayAbilitySpecHandle& SpecHandle : ActiveAbilities->SpecHandle) { if (SpecHandle.IsValid()) { @@ -183,12 +181,12 @@ void UGameFeatureAction_AddAbilities::RemoveActorAbilities(AActor* TargetActor) // Get the interface owner and try to remove the input bindings if (const IMFEA_AbilityInputBinding* const SetupInputInterface = ModularFeaturesHelper::GetAbilityInputBindingInterface(TargetActor, InputBindingOwnerOverride)) { - ModularFeaturesHelper::RemoveAbilityInputInInterfaceOwner(SetupInputInterface->_getUObject(), ActiveAbilities.InputReference); + ModularFeaturesHelper::RemoveAbilityInputInInterfaceOwner(SetupInputInterface->_getUObject(), ActiveAbilities->InputReference); } } else if (IsValid(GetWorld()) && IsValid(GetWorld()->GetGameInstance())) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } ActiveExtensions.Remove(TargetActor); diff --git a/Source/Private/Actions/GameFeatureAction_AddAttribute.cpp b/Source/Private/Actions/GameFeatureAction_AddAttribute.cpp index 34830cc..a0b1f47 100644 --- a/Source/Private/Actions/GameFeatureAction_AddAttribute.cpp +++ b/Source/Private/Actions/GameFeatureAction_AddAttribute.cpp @@ -7,9 +7,13 @@ #include #include +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(GameFeatureAction_AddAttribute) +#endif + void UGameFeatureAction_AddAttribute::OnGameFeatureActivating(FGameFeatureActivatingContext& Context) { - if (!ensureAlways(ActiveExtensions.IsEmpty()) || !ensureAlways(ActiveRequests.IsEmpty())) + if (!ensureAlways(ActiveExtensions.IsEmpty())) { ResetExtension(); } @@ -20,7 +24,6 @@ void UGameFeatureAction_AddAttribute::OnGameFeatureActivating(FGameFeatureActiva void UGameFeatureAction_AddAttribute::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) { Super::OnGameFeatureDeactivating(Context); - ResetExtension(); } @@ -32,16 +35,14 @@ void UGameFeatureAction_AddAttribute::ResetExtension() RemoveAttribute(ExtensionIterator->Key.Get()); } - ActiveRequests.Empty(); + Super::ResetExtension(); } void UGameFeatureAction_AddAttribute::AddToWorld(const FWorldContext& WorldContext) { - if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); - IsValid(ComponentManager) && !TargetPawnClass.IsNull()) + if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); IsValid(ComponentManager) && !TargetPawnClass.IsNull()) { using FHandlerDelegate = UGameFrameworkComponentManager::FExtensionHandlerDelegate; - const FHandlerDelegate ExtensionHandlerDelegate = FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddAttribute::HandleActorExtension); ActiveRequests.Add(ComponentManager->AddExtensionHandler(TargetPawnClass, ExtensionHandlerDelegate)); @@ -50,8 +51,6 @@ void UGameFeatureAction_AddAttribute::AddToWorld(const FWorldContext& WorldConte void UGameFeatureAction_AddAttribute::HandleActorExtension(AActor* Owner, const FName EventName) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("Event %s sent by Actor %s for attribute management."), *EventName.ToString(), *Owner->GetName()); - if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved || EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved) { RemoveAttribute(Owner); @@ -67,7 +66,7 @@ void UGameFeatureAction_AddAttribute::HandleActorExtension(AActor* Owner, const if (Attribute.IsNull()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Attribute is null."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Attribute is null."), *FString(__func__)); } else { @@ -85,7 +84,7 @@ void UGameFeatureAction_AddAttribute::AddAttribute(AActor* TargetActor) } // Get the ability system component of the target actor - if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor)) + if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentInActor(TargetActor)) { // Load and store the AttributeSet Class into a const variable if (const TSubclassOf SetType = Attribute.LoadSynchronous()) @@ -105,18 +104,18 @@ void UGameFeatureAction_AddAttribute::AddAttribute(AActor* TargetActor) // Force the ability system component to replicate the attribute addition AbilitySystemComponent->ForceReplication(); - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Attribute %s added to Actor %s."), *FString(__func__), *SetType->GetName(), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Attribute %s added to Actor %s."), *FString(__func__), *SetType->GetName(), *TargetActor->GetName()); ActiveExtensions.Add(TargetActor, NewSet); } else { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Attribute is invalid."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Attribute is invalid."), *FString(__func__)); } } else { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } } @@ -136,22 +135,21 @@ void UGameFeatureAction_AddAttribute::RemoveAttribute(AActor* TargetActor) } // Get the ability system component of the target actor - if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor)) + if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentInActor(TargetActor)) { // Get the added Attribute Set to the target actor by searching inside the Active Extensions, remove it from the Ability System Component and force a replication -#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1 - if (UAttributeSet* const AttributeToRemove = ActiveExtensions.FindRef(TargetActor).Get()) +#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION == 0 + if (UAttributeSet* const AttributeToRemove = ActiveExtensions.FindRef(TargetActor).Get(); AbilitySystemComponent->GetSpawnedAttributes_Mutable().Remove(AttributeToRemove) != 0) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Removing attribute %s from Actor %s."), *FString(__func__), *AttributeToRemove->GetName(), *TargetActor->GetName()); - - AbilitySystemComponent->RemoveSpawnedAttribute(AttributeToRemove); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Attribute %s removed from Actor %s."), *FString(__func__), *AttributeToRemove->GetName(), *TargetActor->GetName()); AbilitySystemComponent->ForceReplication(); } -#elif ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION == 0 - if (UAttributeSet* const AttributeToRemove = ActiveExtensions.FindRef(TargetActor).Get(); - AbilitySystemComponent->GetSpawnedAttributes_Mutable().Remove(AttributeToRemove) != 0) +#else + if (UAttributeSet* const AttributeToRemove = ActiveExtensions.FindRef(TargetActor).Get()) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Attribute %s removed from Actor %s."), *FString(__func__), *AttributeToRemove->GetName(), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Removing attribute %s from Actor %s."), *FString(__func__), *AttributeToRemove->GetName(), *TargetActor->GetName()); + + AbilitySystemComponent->RemoveSpawnedAttribute(AttributeToRemove); AbilitySystemComponent->ForceReplication(); } #endif @@ -159,7 +157,7 @@ void UGameFeatureAction_AddAttribute::RemoveAttribute(AActor* TargetActor) // We don't need to warn the user if there's no valid world or game instance, since this is a common case when the game is shutting down else if (IsValid(GetWorld()) && IsValid(GetWorld()->GetGameInstance())) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } ActiveExtensions.Remove(TargetActor); diff --git a/Source/Private/Actions/GameFeatureAction_AddEffects.cpp b/Source/Private/Actions/GameFeatureAction_AddEffects.cpp index 749ff60..aef42d9 100644 --- a/Source/Private/Actions/GameFeatureAction_AddEffects.cpp +++ b/Source/Private/Actions/GameFeatureAction_AddEffects.cpp @@ -6,9 +6,13 @@ #include "ModularFeatures_InternalFuncs.h" #include +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(GameFeatureAction_AddEffects) +#endif + void UGameFeatureAction_AddEffects::OnGameFeatureActivating(FGameFeatureActivatingContext& Context) { - if (!ensureAlways(ActiveExtensions.IsEmpty()) || !ensureAlways(ActiveRequests.IsEmpty())) + if (!ensureAlways(ActiveExtensions.IsEmpty())) { ResetExtension(); } @@ -19,7 +23,6 @@ void UGameFeatureAction_AddEffects::OnGameFeatureActivating(FGameFeatureActivati void UGameFeatureAction_AddEffects::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) { Super::OnGameFeatureDeactivating(Context); - ResetExtension(); } @@ -31,16 +34,14 @@ void UGameFeatureAction_AddEffects::ResetExtension() RemoveEffects(ExtensionIterator->Key.Get()); } - ActiveRequests.Empty(); + Super::ResetExtension(); } void UGameFeatureAction_AddEffects::AddToWorld(const FWorldContext& WorldContext) { - if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); - IsValid(ComponentManager) && !TargetPawnClass.IsNull()) + if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); IsValid(ComponentManager) && !TargetPawnClass.IsNull()) { using FHandlerDelegate = UGameFrameworkComponentManager::FExtensionHandlerDelegate; - const FHandlerDelegate ExtensionHandlerDelegate = FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddEffects::HandleActorExtension); ActiveRequests.Add(ComponentManager->AddExtensionHandler(TargetPawnClass, ExtensionHandlerDelegate)); @@ -49,8 +50,6 @@ void UGameFeatureAction_AddEffects::AddToWorld(const FWorldContext& WorldContext void UGameFeatureAction_AddEffects::HandleActorExtension(AActor* Owner, const FName EventName) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("Event %s sent by Actor %s for effects management."), *EventName.ToString(), *Owner->GetName()); - if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved || EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved) { RemoveEffects(Owner); @@ -68,7 +67,7 @@ void UGameFeatureAction_AddEffects::HandleActorExtension(AActor* Owner, const FN { if (Entry.EffectClass.IsNull()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Effect class is null."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Effect class is null."), *FString(__func__)); } else { @@ -87,7 +86,7 @@ void UGameFeatureAction_AddEffects::AddEffects(AActor* TargetActor, const FEffec } // Get the ability system component of the target actor - if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor)) + if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentInActor(TargetActor)) { // Check if there's already added spec data applied to the target actor TArray& SpecData = ActiveExtensions.FindOrAdd(TargetActor); @@ -95,7 +94,7 @@ void UGameFeatureAction_AddEffects::AddEffects(AActor* TargetActor, const FEffec // Load the Effect class into a const variable const TSubclassOf EffectClass = Effect.EffectClass.LoadSynchronous(); - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Adding effect %s level %u to Actor %s with %u SetByCaller params."), *FString(__func__), *EffectClass->GetName(), Effect.EffectLevel, *TargetActor->GetName(), Effect.SetByCallerParams.Num()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Adding effect %s level %u to Actor %s with %u SetByCaller params."), *FString(__func__), *EffectClass->GetName(), Effect.EffectLevel, *TargetActor->GetName(), Effect.SetByCallerParams.Num()); // Create the outgoing spec handle to define the SetByCaller settings and apply the data to the target Ability System Component const FGameplayEffectSpecHandle SpecHandle = AbilitySystemComponent->MakeOutgoingSpec(EffectClass, Effect.EffectLevel, AbilitySystemComponent->MakeEffectContext()); @@ -116,7 +115,7 @@ void UGameFeatureAction_AddEffects::AddEffects(AActor* TargetActor, const FEffec } else { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } } @@ -136,26 +135,27 @@ void UGameFeatureAction_AddEffects::RemoveEffects(AActor* TargetActor) } // Get the active effects and check if it's empty - if (TArray ActiveEffects = ActiveExtensions.FindRef(TargetActor); - !ActiveEffects.IsEmpty()) + if (TArray ActiveEffects = ActiveExtensions.FindRef(TargetActor); !ActiveEffects.IsEmpty()) { // Get the target ability system component - if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor)) + if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentInActor(TargetActor)) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Removing effects from Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Removing effects from Actor %s."), *FString(__func__), *TargetActor->GetName()); // Iterate through the active effects and remove the specified effect by its effect handle if its valid for (const FActiveGameplayEffectHandle& EffectHandle : ActiveEffects) { - if (EffectHandle.IsValid()) + if (!EffectHandle.IsValid()) { - AbilitySystemComponent->RemoveActiveGameplayEffect(EffectHandle); + continue; } + + AbilitySystemComponent->RemoveActiveGameplayEffect(EffectHandle); } } else if (IsValid(GetWorld()) && IsValid(GetWorld()->GetGameInstance())) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } } diff --git a/Source/Private/Actions/GameFeatureAction_AddInputs.cpp b/Source/Private/Actions/GameFeatureAction_AddInputs.cpp index 8e0f1db..40a5ce7 100644 --- a/Source/Private/Actions/GameFeatureAction_AddInputs.cpp +++ b/Source/Private/Actions/GameFeatureAction_AddInputs.cpp @@ -10,9 +10,13 @@ #include #include +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(GameFeatureAction_AddInputs) +#endif + void UGameFeatureAction_AddInputs::OnGameFeatureActivating(FGameFeatureActivatingContext& Context) { - if (!ensureAlways(ActiveExtensions.IsEmpty()) || !ensureAlways(ActiveRequests.IsEmpty())) + if (!ensureAlways(ActiveExtensions.IsEmpty())) { ResetExtension(); } @@ -23,7 +27,6 @@ void UGameFeatureAction_AddInputs::OnGameFeatureActivating(FGameFeatureActivatin void UGameFeatureAction_AddInputs::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) { Super::OnGameFeatureDeactivating(Context); - ResetExtension(); } @@ -35,16 +38,14 @@ void UGameFeatureAction_AddInputs::ResetExtension() RemoveActorInputs(ExtensionIterator->Key.Get()); } - ActiveRequests.Empty(); + Super::ResetExtension(); } void UGameFeatureAction_AddInputs::AddToWorld(const FWorldContext& WorldContext) { - if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); - IsValid(ComponentManager) && !TargetPawnClass.IsNull()) + if (UGameFrameworkComponentManager* const ComponentManager = GetGameFrameworkComponentManager(WorldContext); IsValid(ComponentManager) && !TargetPawnClass.IsNull()) { using FHandlerDelegate = UGameFrameworkComponentManager::FExtensionHandlerDelegate; - const FHandlerDelegate ExtensionHandlerDelegate = FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddInputs::HandleActorExtension); ActiveRequests.Add(ComponentManager->AddExtensionHandler(TargetPawnClass, ExtensionHandlerDelegate)); @@ -53,8 +54,6 @@ void UGameFeatureAction_AddInputs::AddToWorld(const FWorldContext& WorldContext) void UGameFeatureAction_AddInputs::HandleActorExtension(AActor* Owner, const FName EventName) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("Event %s sent by Actor %s for inputs management."), *EventName.ToString(), *Owner->GetName()); - if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved || EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved) { RemoveActorInputs(Owner); @@ -70,7 +69,7 @@ void UGameFeatureAction_AddInputs::HandleActorExtension(AActor* Owner, const FNa if (InputMappingContext.IsNull()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Input Mapping Context is null."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Input Mapping Context is null."), *FString(__func__)); } else { @@ -103,7 +102,7 @@ void UGameFeatureAction_AddInputs::AddActorInputs(AActor* TargetActor) // Load the Input Mapping context and store it into a variable UInputMappingContext* const InputMapping = InputMappingContext.LoadSynchronous(); - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Adding Enhanced Input Mapping %s to Actor %s."), *FString(__func__), *InputMapping->GetName(), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Adding Enhanced Input Mapping %s to Actor %s."), *FString(__func__), *InputMapping->GetName(), *TargetActor->GetName()); // Add the loaded mapping context into the enhanced input subsystem Subsystem->AddMappingContext(InputMapping, MappingPriority); @@ -115,7 +114,7 @@ void UGameFeatureAction_AddInputs::AddActorInputs(AActor* TargetActor) const TWeakObjectPtr FunctionOwner = ModularFeaturesHelper::GetPawnInputOwner(TargetPawn, InputBindingOwnerOverride); if (!FunctionOwner.IsValid()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to get the function owner using the Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to get the function owner using the Actor %s."), *FString(__func__), *TargetActor->GetName()); return; } @@ -123,7 +122,7 @@ void UGameFeatureAction_AddInputs::AddActorInputs(AActor* TargetActor) const TWeakObjectPtr InputComponent = ModularFeaturesHelper::GetEnhancedInputComponentInPawn(TargetPawn); if (!InputComponent.IsValid()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find InputComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find InputComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); return; } @@ -133,7 +132,7 @@ void UGameFeatureAction_AddInputs::AddActorInputs(AActor* TargetActor) } else if (TargetPawn->IsPawnControlled()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find PlayerController on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find PlayerController on Actor %s."), *FString(__func__), *TargetActor->GetName()); } } @@ -160,13 +159,12 @@ void UGameFeatureAction_AddInputs::RemoveActorInputs(AActor* TargetActor) // Try to get the enhanced input subsystem from the pawn if (UEnhancedInputLocalPlayerSubsystem* const Subsystem = GetEnhancedInputComponentFromPawn(TargetPawn)) { - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Removing Enhanced Input Mapping %s from Actor %s."), *FString(__func__), *ActiveInputData->Mapping->GetName(), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Removing Enhanced Input Mapping %s from Actor %s."), *FString(__func__), *ActiveInputData->Mapping->GetName(), *TargetActor->GetName()); // Try to get the enhanced input component of the target pawn - if (const TWeakObjectPtr InputComponent = ModularFeaturesHelper::GetEnhancedInputComponentInPawn(TargetPawn); - !InputComponent.IsValid()) + if (const TWeakObjectPtr InputComponent = ModularFeaturesHelper::GetEnhancedInputComponentInPawn(TargetPawn); !InputComponent.IsValid()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find InputComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find InputComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } else { @@ -208,14 +206,14 @@ void UGameFeatureAction_AddInputs::SetupActionBindings(AActor* TargetActor, UObj // Check if the action input is valid if (ActionInput.IsNull()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Action Input is null."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Action Input is null."), *FString(__func__)); continue; } // Load and store the Action Input into a variable UInputAction* const InputAction = ActionInput.LoadSynchronous(); - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Binding Action Input %s to Actor %s."), *FString(__func__), *InputAction->GetName(), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Binding Action Input %s to Actor %s."), *FString(__func__), *InputAction->GetName(), *TargetActor->GetName()); // Iterate through all function binding data to bind the UFunctions to it's corresponding input for (const auto& [FunctionName, Triggers] : FunctionBindingData) @@ -260,7 +258,7 @@ UEnhancedInputLocalPlayerSubsystem* UGameFeatureAction_AddInputs::GetEnhancedInp UEnhancedInputLocalPlayerSubsystem* const Subsystem = LocalPlayer->GetSubsystem(); if (!IsValid(Subsystem)) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: LocalPlayer %s has no EnhancedInputLocalPlayerSubsystem."), *FString(__func__), *LocalPlayer->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: LocalPlayer %s has no EnhancedInputLocalPlayerSubsystem."), *FString(__func__), *LocalPlayer->GetName()); return nullptr; } @@ -282,14 +280,14 @@ FGameplayAbilitySpec UGameFeatureAction_AddInputs::GetAbilitySpecInformationFrom // If the user wants to find a active ability spec, we'll try to get the ability system component of the target actor and get the spec using the specified ability class if (AbilityBindingData.bFindAbilitySpec) { - if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor)) + if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentInActor(TargetActor)) { // We're not using the InputID to search for existing spec because more than 1 abilities can have the same Input Id AbilitySystemComponent->FindAbilitySpecFromClass(TSubclassOf(AbilityBindingData.AbilityClass.LoadSynchronous())); } else { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName()); } } // If we are not using an existing spec, we'll create a basic spec just to pass some parameters to the ability binding diff --git a/Source/Private/Actions/GameFeatureAction_SpawnActors.cpp b/Source/Private/Actions/GameFeatureAction_SpawnActors.cpp index c86b751..49565e8 100644 --- a/Source/Private/Actions/GameFeatureAction_SpawnActors.cpp +++ b/Source/Private/Actions/GameFeatureAction_SpawnActors.cpp @@ -3,8 +3,13 @@ // Repo: https://github.com/lucoiso/UEModularFeatures_ExtraActions #include "Actions/GameFeatureAction_SpawnActors.h" +#include "LogModularFeatures_ExtraActions.h" #include +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(GameFeatureAction_SpawnActors) +#endif + void UGameFeatureAction_SpawnActors::OnGameFeatureActivating(FGameFeatureActivatingContext& Context) { if (!ensureAlways(SpawnedActors.IsEmpty())) @@ -66,18 +71,17 @@ void UGameFeatureAction_SpawnActors::SpawnActors(UWorld* WorldReference) // Check if the soft reference is null if (ActorClass.IsNull()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Actor class is null."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Actor class is null."), *FString(__func__)); continue; } // Load the actor class and store it into a variable TSubclassOf ClassToSpawn = ActorClass.LoadSynchronous(); - UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Spawning actor %s on world %s"), *FString(__func__), *ClassToSpawn->GetName(), *WorldReference->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Spawning actor %s on world %s"), *FString(__func__), *ClassToSpawn->GetName(), *WorldReference->GetName()); // Spawn the actor and add it to the spawned array - AActor* const SpawnedActor = WorldReference->SpawnActor(ClassToSpawn, SpawnTransform); - SpawnedActors.Add(SpawnedActor); + SpawnedActors.Add(WorldReference->SpawnActor(ClassToSpawn, SpawnTransform)); } } @@ -86,10 +90,13 @@ void UGameFeatureAction_SpawnActors::DestroyActors() // Iterate through all spawned actors and destroy all valid actors for (const TWeakObjectPtr& ActorPtr : SpawnedActors) { - if (ActorPtr.IsValid()) + if (!ActorPtr.IsValid()) { - ActorPtr->Destroy(); + continue; } + + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Display, TEXT("%s: Destroying actor %s"), *FString(__func__), *ActorPtr->GetName()); + ActorPtr->Destroy(); } SpawnedActors.Empty(); diff --git a/Source/Private/Actions/GameFeatureAction_WorldActionBase.cpp b/Source/Private/Actions/GameFeatureAction_WorldActionBase.cpp index f932f95..c791b59 100644 --- a/Source/Private/Actions/GameFeatureAction_WorldActionBase.cpp +++ b/Source/Private/Actions/GameFeatureAction_WorldActionBase.cpp @@ -4,20 +4,33 @@ #include "Actions/GameFeatureAction_WorldActionBase.h" +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(GameFeatureAction_WorldActionBase) +#endif + void UGameFeatureAction_WorldActionBase::OnGameFeatureActivating(FGameFeatureActivatingContext& Context) { Super::OnGameFeatureActivating(Context); + if (!ensureAlways(ActiveRequests.IsEmpty())) + { + ResetExtension(); + } + + const FGameFeatureStateChangeContext StateChangeContext(Context); + // When the game instance starts, will perform the modular feature activation behavior - GameInstanceStartHandle = FWorldDelegates::OnStartGameInstance.AddUObject(this, &UGameFeatureAction_WorldActionBase::HandleGameInstanceStart, FGameFeatureStateChangeContext(Context)); + GameInstanceStartHandle = FWorldDelegates::OnStartGameInstance.AddUObject(this, &UGameFeatureAction_WorldActionBase::HandleGameInstanceStart, StateChangeContext); // Useful to activate the feature even if the game instance has already started for (const FWorldContext& WorldContext : GEngine->GetWorldContexts()) { - if (Context.ShouldApplyToWorldContext(WorldContext)) + if (!Context.ShouldApplyToWorldContext(WorldContext)) { - AddToWorld(WorldContext); + continue; } + + AddToWorld(WorldContext); } } @@ -28,6 +41,11 @@ void UGameFeatureAction_WorldActionBase::OnGameFeatureDeactivating(FGameFeatureD FWorldDelegates::OnStartGameInstance.Remove(GameInstanceStartHandle); } +void UGameFeatureAction_WorldActionBase::ResetExtension() +{ + ActiveRequests.Empty(); +} + UGameFrameworkComponentManager* UGameFeatureAction_WorldActionBase::GetGameFrameworkComponentManager(const FWorldContext& WorldContext) const { if (!IsValid(WorldContext.World()) || !WorldContext.World()->IsGameWorld()) @@ -40,8 +58,10 @@ UGameFrameworkComponentManager* UGameFeatureAction_WorldActionBase::GetGameFrame void UGameFeatureAction_WorldActionBase::HandleGameInstanceStart(UGameInstance* GameInstance, const FGameFeatureStateChangeContext ChangeContext) { - if (ChangeContext.ShouldApplyToWorldContext(*GameInstance->GetWorldContext())) + if (!ChangeContext.ShouldApplyToWorldContext(*GameInstance->GetWorldContext())) { - AddToWorld(*GameInstance->GetWorldContext()); + return; } + + AddToWorld(*GameInstance->GetWorldContext()); } diff --git a/Source/Private/Interfaces/MFEA_AbilityInputBinding.cpp b/Source/Private/Interfaces/MFEA_AbilityInputBinding.cpp index 6a4b5fb..a1fc929 100644 --- a/Source/Private/Interfaces/MFEA_AbilityInputBinding.cpp +++ b/Source/Private/Interfaces/MFEA_AbilityInputBinding.cpp @@ -2,4 +2,8 @@ // Year: 2022 // Repo: https://github.com/lucoiso/UEModularFeatures_ExtraActions -#include "Interfaces/MFEA_AbilityInputBinding.h" \ No newline at end of file +#include "Interfaces/MFEA_AbilityInputBinding.h" + +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(MFEA_AbilityInputBinding) +#endif \ No newline at end of file diff --git a/Source/Private/LogModularFeatures_ExtraActions.cpp b/Source/Private/LogModularFeatures_ExtraActions.cpp index fa23fe8..f5a0f80 100644 --- a/Source/Private/LogModularFeatures_ExtraActions.cpp +++ b/Source/Private/LogModularFeatures_ExtraActions.cpp @@ -4,4 +4,5 @@ #include "LogModularFeatures_ExtraActions.h" -DEFINE_LOG_CATEGORY(LogGameplayFeaturesExtraActions); \ No newline at end of file +DEFINE_LOG_CATEGORY(LogGameplayFeaturesExtraActions); +DEFINE_LOG_CATEGORY(LogGameplayFeaturesExtraActions_Internal); \ No newline at end of file diff --git a/Source/Private/MFEA_Settings.cpp b/Source/Private/MFEA_Settings.cpp index 45bfb02..94986e6 100644 --- a/Source/Private/MFEA_Settings.cpp +++ b/Source/Private/MFEA_Settings.cpp @@ -5,8 +5,44 @@ #pragma once #include "MFEA_Settings.h" +#include "LogModularFeatures_ExtraActions.h" -UMFEA_Settings::UMFEA_Settings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer), bEnableAbilityAutoBinding(false), AbilityBindingMode(EAbilityBindingMode::InputID), InputBindingOwner(EInputBindingOwner::Controller) +#ifdef UE_INLINE_GENERATED_CPP_BY_NAME +#include UE_INLINE_GENERATED_CPP_BY_NAME(MFEA_Settings) +#endif + +UMFEA_Settings::UMFEA_Settings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer), bEnableAbilityAutoBinding(false), bEnableInternalLogs(false), AbilityBindingMode(EAbilityBindingMode::InputID), InputBindingOwner(EInputBindingOwner::Controller) { CategoryName = TEXT("Plugins"); } + +const UMFEA_Settings* UMFEA_Settings::Get() +{ + static const UMFEA_Settings* const Instance = GetDefault(); + return Instance; +} + +#if WITH_EDITOR +void UMFEA_Settings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) +{ + Super::PostEditChangeProperty(PropertyChangedEvent); + + if (PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(UMFEA_Settings, bEnableInternalLogs)) + { + ToggleInternalLogs(); + } +} +#endif + +void UMFEA_Settings::PostInitProperties() +{ + Super::PostInitProperties(); + ToggleInternalLogs(); +} + +void UMFEA_Settings::ToggleInternalLogs() +{ +#if !UE_BUILD_SHIPPING + LogGameplayFeaturesExtraActions_Internal.SetVerbosity(bEnableInternalLogs ? ELogVerbosity::Display : ELogVerbosity::NoLogging); +#endif +} diff --git a/Source/Private/ModularFeatures_InternalFuncs.h b/Source/Private/ModularFeatures_InternalFuncs.h index ded2ed1..a1b6760 100644 --- a/Source/Private/ModularFeatures_InternalFuncs.h +++ b/Source/Private/ModularFeatures_InternalFuncs.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include "Interfaces/MFEA_AbilityInputBinding.h" @@ -39,19 +39,18 @@ namespace ModularFeaturesHelper return true; } - UAbilitySystemComponent* GetAbilitySystemComponentByActor(AActor* InActor) + UAbilitySystemComponent* GetAbilitySystemComponentInActor(AActor* InActor) { - const IAbilitySystemInterface* const InterfaceOwner = Cast(InActor); - return InterfaceOwner != nullptr ? InterfaceOwner->GetAbilitySystemComponent() : InActor->FindComponentByClass(); + return UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(InActor); } EInputBindingOwner GetValidatedInputBindingOwner(const EInputBindingOwnerOverride& InOwner) { switch (InOwner) { - case EInputBindingOwnerOverride::Pawn: return EInputBindingOwner::Pawn; - case EInputBindingOwnerOverride::Controller: return EInputBindingOwner::Controller; - default: break; + case EInputBindingOwnerOverride::Pawn: return EInputBindingOwner::Pawn; + case EInputBindingOwnerOverride::Controller: return EInputBindingOwner::Controller; + default: break; } return GetPluginSettings()->InputBindingOwner; @@ -108,7 +107,7 @@ namespace ModularFeaturesHelper { if (GetPluginSettings()->InputIDEnumeration.IsNull()) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: bUseInputEnumeration is set to true but Enumeration class is null!"), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: bUseInputEnumeration is set to true but Enumeration class is null!"), *FString(__func__)); return nullptr; } @@ -120,7 +119,7 @@ namespace ModularFeaturesHelper { if (!TargetInterfaceOwner) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to setup input binding on Actor %s due to a invalid interface owner."), *FString(__func__), *TargetInterfaceOwner->_getUObject()->GetName()); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to setup input binding on Actor %s due to a invalid interface owner."), *FString(__func__), *TargetInterfaceOwner->_getUObject()->GetName()); return false; } @@ -164,7 +163,7 @@ namespace ModularFeaturesHelper { if (!IsValid(InterfaceOwner)) { - UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to remove input binding due to invalid interface owner."), *FString(__func__)); + UE_LOG(LogGameplayFeaturesExtraActions_Internal, Error, TEXT("%s: Failed to remove input binding due to invalid interface owner."), *FString(__func__)); return; } diff --git a/Source/Public/Actions/GameFeatureAction_WorldActionBase.h b/Source/Public/Actions/GameFeatureAction_WorldActionBase.h index 236c265..2624a92 100644 --- a/Source/Public/Actions/GameFeatureAction_WorldActionBase.h +++ b/Source/Public/Actions/GameFeatureAction_WorldActionBase.h @@ -41,6 +41,8 @@ class UGameFeatureAction_WorldActionBase : public UGameFeatureAction UGameFrameworkComponentManager* GetGameFrameworkComponentManager(const FWorldContext& WorldContext) const; TArray ActiveRequests; + + virtual void ResetExtension(); private: void HandleGameInstanceStart(UGameInstance* GameInstance, FGameFeatureStateChangeContext ChangeContext); diff --git a/Source/Public/Interfaces/MFEA_AbilityInputBinding.h b/Source/Public/Interfaces/MFEA_AbilityInputBinding.h index 8a9ab87..d4eb1cd 100644 --- a/Source/Public/Interfaces/MFEA_AbilityInputBinding.h +++ b/Source/Public/Interfaces/MFEA_AbilityInputBinding.h @@ -25,8 +25,9 @@ class UMFEA_AbilityInputBinding : public UInterface /* Your pawn or controller need this inferface to accept ability input bindings */ class MODULARFEATURES_EXTRAACTIONS_API IMFEA_AbilityInputBinding { - GENERATED_IINTERFACE_BODY() - + GENERATED_BODY() + +public: /* Setup ability bind using input id - AbilityLocalInputPressed(InputID)*/ UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "MF Extra Actions | Modular Interfaces") void SetupAbilityBindingByInput(UInputAction* Action, const int32 InputID); diff --git a/Source/Public/LogModularFeatures_ExtraActions.h b/Source/Public/LogModularFeatures_ExtraActions.h index adccdba..ed3ce10 100644 --- a/Source/Public/LogModularFeatures_ExtraActions.h +++ b/Source/Public/LogModularFeatures_ExtraActions.h @@ -10,4 +10,5 @@ * */ -DECLARE_LOG_CATEGORY_EXTERN(LogGameplayFeaturesExtraActions, Display, All); \ No newline at end of file +DECLARE_LOG_CATEGORY_EXTERN(LogGameplayFeaturesExtraActions, Display, All); +DECLARE_LOG_CATEGORY_EXTERN(LogGameplayFeaturesExtraActions_Internal, NoLogging, All); \ No newline at end of file diff --git a/Source/Public/MFEA_Settings.h b/Source/Public/MFEA_Settings.h index 5654339..bc3716e 100644 --- a/Source/Public/MFEA_Settings.h +++ b/Source/Public/MFEA_Settings.h @@ -34,6 +34,7 @@ class MODULARFEATURES_EXTRAACTIONS_API UMFEA_Settings : public UDeveloperSetting public: explicit UMFEA_Settings(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get()); + static const UMFEA_Settings* Get(); private: /* Work in Progress: If true, will auto bind the ability input directly using the given Input Action. Will be added in a next update. */ @@ -41,6 +42,10 @@ class MODULARFEATURES_EXTRAACTIONS_API UMFEA_Settings : public UDeveloperSetting bool bEnableAbilityAutoBinding; public: + /* Will print extra internal informations in log */ + UPROPERTY(GlobalConfig, EditAnywhere, Category = "Settings", Meta = (DisplayName = "Enable Internal Logs")) + bool bEnableInternalLogs; + /* Determine the binding mode that will be used by this plugin - This choice affects which function from IMFEA_AbilityInputBinding interface will be used to bind the abilities */ UPROPERTY(GlobalConfig, EditAnywhere, Category = "Settings", Meta = (EditCondition = "!bEnableAbilityAutoBinding")) EAbilityBindingMode AbilityBindingMode; @@ -52,4 +57,14 @@ class MODULARFEATURES_EXTRAACTIONS_API UMFEA_Settings : public UDeveloperSetting /* Determine if the ability binding will be performed to the pawn or its controller - Must be the owner of the binding interface. Can be overrided by actions. */ UPROPERTY(GlobalConfig, EditAnywhere, Category = "Settings", Meta = (DisplayName = "Default Input Binding Owner")) EInputBindingOwner InputBindingOwner; + +protected: +#if WITH_EDITOR + virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; +#endif + + virtual void PostInitProperties() override; + +private: + void ToggleInternalLogs(); };