{"id":13,"date":"2021-01-24T21:43:06","date_gmt":"2021-01-24T21:43:06","guid":{"rendered":"https:\/\/www.thegames.dev\/?p=13"},"modified":"2021-01-24T22:48:47","modified_gmt":"2021-01-24T22:48:47","slug":"test-post","status":"publish","type":"post","link":"https:\/\/www.thegames.dev\/?p=13","title":{"rendered":"Applying Gameplay Tags from SourceObject into Effect Spec"},"content":{"rendered":"\n<p>In my game, i wanted to grab Gameplay Tags from the source object if possible, and apply them into the captured tags of the Gameplay Effect Spec. With this in mind, i went searching through the system, and found the following function gets called UGameplayAbility::ApplyAbilityTagsToGameplayEffectSpec. I was like great that is exactly what i need, so i went and overrode this function.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: Relevant Code:; notranslate\" title=\"Relevant Code:\">\nvoid UKaosGameplayAbility::ApplyAbilityTagsToGameplayEffectSpec(FGameplayEffectSpec&amp; Spec, FGameplayAbilitySpec* AbilitySpec) const\n{\n\tFGameplayTagContainer&amp; CapturedSourceTags = Spec.CapturedSourceTags.GetSpecTags();\n\n\tCapturedSourceTags.AppendTags(AbilityTags);\n\n\tconst UKaosWorldItemDefinition* SourceObjAsItemDefinition = GetCurrentSourceItemDefinition();\n\tif (SourceObjAsItemDefinition)\n\t{\n\t\tFGameplayTagContainer ItemDefTags;\n\t\tSourceObjAsItemDefinition-&gt;GetOwnedGameplayTags(ItemDefTags);\n\n\t\tCapturedSourceTags.AppendTags(ItemDefTags);\n\t}\n\t\n\t\/\/ Allow the source object of the ability to propagate tags along as well\n\tif (AbilitySpec)\n\t{\n\t\tCapturedSourceTags.AppendTags(AbilitySpec-&gt;DynamicAbilityTags);\n\t\t\n\t\tconst IGameplayTagAssetInterface* SourceObjAsTagInterface = Cast&lt;IGameplayTagAssetInterface&gt;(AbilitySpec-&gt;SourceObject);\n\t\tif (SourceObjAsTagInterface)\n\t\t{\n\t\t\tFGameplayTagContainer SourceObjTags;\n\t\t\tSourceObjAsTagInterface-&gt;GetOwnedGameplayTags(SourceObjTags);\n\n\t\t\tCapturedSourceTags.AppendTags(SourceObjTags);\n\t\t}\n\n\t\t\/\/ Copy SetByCallerMagnitudes \n\t\tSpec.MergeSetByCallerMagnitudes(AbilitySpec-&gt;SetByCallerTagMagnitudes);\n\t}\n}\n<\/pre><\/div>\n\n\n<p>The relevant lines to take note of is <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: Relevant Code:; notranslate\" title=\"Relevant Code:\">\n\tconst UKaosWorldItemDefinition* SourceObjAsItemDefinition = GetCurrentSourceItemDefinition();\n\tif (SourceObjAsItemDefinition)\n\t{\n\t\tFGameplayTagContainer ItemDefTags;\n\t\tSourceObjAsItemDefinition-&gt;GetOwnedGameplayTags(ItemDefTags);\n\n\t\tCapturedSourceTags.AppendTags(ItemDefTags);\n\t}\n<\/pre><\/div>\n\n\n<p>With this, i grab the current source items definition. This is purely for my games purpose, but it shows that you can grab tags from anywhere, but what you are really interested in is pulling it from the SourceObject that would implement the IGameplayTagAssetInterface. This is seen in the first code block under the if (AbilitySpec), the relevant code is here:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: Relevant Code:; notranslate\" title=\"Relevant Code:\">\n    const IGameplayTagAssetInterface* SourceObjAsTagInterface = Cast&lt;IGameplayTagAssetInterface&gt;(AbilitySpec-&gt;SourceObject);\n    if (SourceObjAsTagInterface)\n    {\n        FGameplayTagContainer SourceObjTags;\n        SourceObjAsTagInterface-&gt;GetOwnedGameplayTags(SourceObjTags);\n\n        CapturedSourceTags.AppendTags(SourceObjTags);\n    }\n<\/pre><\/div>\n\n\n<p>So what the above does, is gets the SourceObject from the AbilitySpec, then casts it to the IGameplayTagAssetInterface. If this is successful, we can literally grab the Owned GameplayTags and populate our CapturedSourceTags.<\/p>\n\n\n\n<p>And there you have it, a nice way to capture tags from Source Objects, and automatically get them applied to your GameplayEffect when used in an ability with that Source Object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my game, i wanted to grab Gameplay Tags from the source object if possible, and apply them into the captured tags of the Gameplay Effect Spec. With this in mind, i went searching through the system, and found the following function gets called UGameplayAbility::ApplyAbilityTagsToGameplayEffectSpec. I was like great that is exactly what i need, <a href=\"https:\/\/www.thegames.dev\/?p=13\" class=\"more-link\">&#8230;<span class=\"screen-reader-text\">  Applying Gameplay Tags from SourceObject into Effect Spec<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-gameplay-ability-system"],"rise-blocks_total_comments":0,"rise-blocks_categories":[{"term_id":4,"name":"Gameplay Ability System","slug":"gameplay-ability-system","term_group":0,"term_taxonomy_id":4,"taxonomy":"category","description":"Unreal Engine's Gameplay Ability System (GAS)","parent":2,"count":16,"filter":"raw","cat_ID":4,"category_count":16,"category_description":"Unreal Engine's Gameplay Ability System (GAS)","cat_name":"Gameplay Ability System","category_nicename":"gameplay-ability-system","category_parent":2}],"rise-blocks_excerpt":"In my game, i wanted to grab Gameplay Tags from the source object if possible, and apply them into the captured tags of the Gameplay Effect Spec. With this in mind, i went searching through the system, and found the following function gets called UGameplayAbility::ApplyAbilityTagsToGameplayEffectSpec. I was like great that is exactly what i need, so i went and overrode..","_links":{"self":[{"href":"https:\/\/www.thegames.dev\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thegames.dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thegames.dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thegames.dev\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thegames.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":5,"href":"https:\/\/www.thegames.dev\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":49,"href":"https:\/\/www.thegames.dev\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/49"}],"wp:attachment":[{"href":"https:\/\/www.thegames.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thegames.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thegames.dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}