From 51c168dc5ea4377d8eba272f6179eb275c87d54a Mon Sep 17 00:00:00 2001 From: Damian Nowakowski Date: Thu, 28 Oct 2021 09:19:11 +0200 Subject: [PATCH 1/3] Added note about AttributeSet being Transient. This is something me and my team encounter lately. When someone was playing a game in the editor - values inside AttributeSet changed. Then, when a character blueprint was duplicated - these changed values were moved to a new character blueprint (but as a default values). This was leading us to some very strange and difficult to track issues. Creating objects, that are not components inside of actor's constructor is very risky and unsafe anyway, just like binding delegates inside the constructor. The best way to mitigate such issues is to set these properties to be Transient, so they won't serialize themselves during gameplay. I'm not sure if the written note is descriptive enough, but I think it is a good idea to note about this problem, as designers usually love to copy-paste blueprints ;) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fb3585ff..5b1621f5 100644 --- a/README.md +++ b/README.md @@ -473,6 +473,8 @@ virtual void StunTagChanged(const FGameplayTag CallbackTag, int32 NewCount); **Tip:** If you don't want an `Attribute` to show up in the Editor's list of `Attributes`, you can use the `Meta = (HideInDetailsView)` `property specifier`. +**Note:** Set the `AttributeSet` to be a `Transient` property. Because it is not a Component it's creation inside an actor's constructor is not safe. Having it not Transient might lead to hard to track issues when duplicating character's Blueprints. + **[⬆ Back to Top](#table-of-contents)** From ecdce88ee1aa89b3d95604e5d4a5e50a8acfed22 Mon Sep 17 00:00:00 2001 From: Damian Nowakowski Date: Thu, 8 Jun 2023 13:05:42 +0200 Subject: [PATCH 2/3] reworking previous commit --- README.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b1621f5..01f9850b 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,8 @@ The best documentation will always be the plugin source code. > 9.2 [`ScriptStructCache` errors](#troubleshooting-scriptstructcache) > 9.3 [Animation Montages are not replicating to clients](#troubleshooting-replicatinganimmontages) > 9.4 [Duplicating Blueprint Actors is setting AttributeSets to nullptr](#troubleshooting-duplicatingblueprintactors) +>       9.4.1 [Not creating `AttributeSet` in the constructor](#troubleshooting-duplicatingblueprintactors-no-constructor) +>       9.4.2 [Making `AttributeSet` `Transient`](#troubleshooting-duplicatingblueprintactors-no-transient) > 1. [Common GAS Acronyms](#acronyms) > 1. [Other Resources](#resources) > 11.1 [Q&A With Epic Game's Dave Ratti](#resources-daveratti) @@ -473,8 +475,6 @@ virtual void StunTagChanged(const FGameplayTag CallbackTag, int32 NewCount); **Tip:** If you don't want an `Attribute` to show up in the Editor's list of `Attributes`, you can use the `Meta = (HideInDetailsView)` `property specifier`. -**Note:** Set the `AttributeSet` to be a `Transient` property. Because it is not a Component it's creation inside an actor's constructor is not safe. Having it not Transient might lead to hard to track issues when duplicating character's Blueprints. - **[⬆ Back to Top](#table-of-contents)** @@ -2984,7 +2984,11 @@ Make sure that you're using the `PlayMontageAndWait` Blueprint node instead of ` ### 9.4 Duplicating Blueprint Actors is setting AttributeSets to nullptr -There is a [bug in Unreal Engine](https://issues.unrealengine.com/issue/UE-81109) that will set `AttributeSet` pointers on your classes to nullptr for Blueprint Actor classes that are duplicated from existing Blueprint Actor classes. There are a few workarounds for this. I've had success not creating bespoke `AttributeSet` pointers on my classes (no pointer in the .h, not calling `CreateDefaultSubobject` in the constructor) and instead just directly adding `AttributeSets` to the `ASC` in `PostInitializeComponents()` (not shown in the Sample Project). The replicated `AttributeSets` will still live in the `ASC's` `SpawnedAttributes` array. It would look something like this: +There is a [bug in Unreal Engine](https://issues.unrealengine.com/issue/UE-81109) that will set `AttributeSet` pointers on your classes to nullptr for Blueprint Actor classes that are duplicated from existing Blueprint Actor classes. There are a few workarounds for this: + + +#### 9.4.1 Not creating `AttributeSet` in the constructor +I've had success not creating bespoke `AttributeSet` pointers on my classes (no pointer in the .h, not calling `CreateDefaultSubobject` in the constructor) and instead just directly adding `AttributeSets` to the `ASC` in `PostInitializeComponents()` (not shown in the Sample Project). The replicated `AttributeSets` will still live in the `ASC's` `SpawnedAttributes` array. It would look something like this: ```c++ void AGDPlayerState::PostInitializeComponents() @@ -3035,6 +3039,18 @@ if (AbilitySystemComponent) As a reminder, the `ASC` only ever expects at most one `AttributeSet` object per `AttributeSet` class. + +#### 9.4.2 Making `AttributeSet` `Transient` +The other workaround for this issue, which seems to work, is to set the `AttributeSet` object to be `Transient`: + +```c++ +UPROPERTY(Transient) +class UGDAttributeSetBase* AttributeSetBase; +``` + +Thanks to that, even when the `AttributeSet` is created in the constructor it won't be serialized and copied when duplicating Blueprint Actor. + + **[⬆ Back to Top](#table-of-contents)** From 8c19ee451ecc4ce5082d143c8f6845b47876e851 Mon Sep 17 00:00:00 2001 From: Damian Nowakowski Date: Thu, 8 Jun 2023 13:07:14 +0200 Subject: [PATCH 3/3] fixed link macros --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01f9850b..93fde087 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ The best documentation will always be the plugin source code. > 9.3 [Animation Montages are not replicating to clients](#troubleshooting-replicatinganimmontages) > 9.4 [Duplicating Blueprint Actors is setting AttributeSets to nullptr](#troubleshooting-duplicatingblueprintactors) >       9.4.1 [Not creating `AttributeSet` in the constructor](#troubleshooting-duplicatingblueprintactors-no-constructor) ->       9.4.2 [Making `AttributeSet` `Transient`](#troubleshooting-duplicatingblueprintactors-no-transient) +>       9.4.2 [Making `AttributeSet` `Transient`](#troubleshooting-duplicatingblueprintactors-transient) > 1. [Common GAS Acronyms](#acronyms) > 1. [Other Resources](#resources) > 11.1 [Q&A With Epic Game's Dave Ratti](#resources-daveratti)