Duplicating an actor with an AttributeSet fails

If I have a blueprint class where the C++ parent has an AttributeSet created in the constructor and I duplicate it and then try to instantiate the duplicated class, the AttributeSet will be null. This is resolved by changing the duplicate blueprint’s parent class to anything else and then reparenting to the original parent.

This only seems to happen to the AttributeSet and only if I duplicate the class. Any ideas why this happens? Is this a known bug with AttributeSets?

It’s a bug in the Engine.

Since I just had to deal with this, here is a workaround.

Create your attribute sets in PreInitializeComponents() instead of the constructor.

Example:
void ASomeActor::PreInitializeComponents()
{
Super::PreInitializeComponents();
CoreAttributes = NewObject(this, TEXT(“CoreAttributes”));
}

As long as you store the set as a Uproperty pointer on the class it will be picked up by the GAS component and also GCed.

Older engine versions also had the issue of null garbage being left in the component, but 4.25 added a check for that in UAbilitySystemComponent::InitializeComponent().

1 Like