I’m probably a bit confused as to the basics here. Let’s say I have these types:
UCLASS()
class UTestMember : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
int32 Value = 0;
};
UCLASS()
class UTestContainer : public UObject
{
GENERATED_BODY()
public:
UTestContainer()
{
MemberA = CreateDefaultSubobject<UTestMember>(FName(TEXT("MA")));
MemberB = CreateDefaultSubobject<UTestMember>(FName(TEXT("MB")));
}
UPROPERTY(Transient, VisibleAnywhere)
UTestMember* MemberA;
UPROPERTY(Transient, VisibleAnywhere)
UTestMember* MemberB;
};
In some component, I create an instance of UTestContainer (at edit-time):
TestContainer = NewObject<UTestContainer>(this, UTestContainer::StaticClass(), FName(TEXT("TisAFineDay")));
where TestContainer is declared as:
UPROPERTY(EditAnywhere, Category="Test")
UTestContainer* TestContainer = nullptr;
I edit the values in MemberA and MemberB in a few different components and note that they each hold unique values for UTestMember::Value. On save, however, they are not persisted since transient has been specified. On load they take their value from the CDO, which I guess is expected. This is the instance data I’m talking about. If I remove the transient specifier, data is persisted and all seems well. In this case I might have been lucky as there was no recycling happening in NewObject, bit hard to tell. But I suppose I could guarantee proper behavior by adding the DefaultToInstanced class specifier to UTestMember? (Just like UActorComponent.)
There is likely something wrong with my reasoning, but what?