Download

DefaultToInstanced/Instanced not working as I would expect?

I made a class UTeamDataAsset derived from UDataAsset. I then made a DataAsset in the editor based on UTeamDataAsset called BlueprintTeamDataAsset. Ideally what I want is to be able to populate an array with preset BlueprintTeamDataAssets in the editor, then, when I press play, have instances of those BlueprintTeamDataAssets to work with so I don’t end up editing the originals. I’m not particularly concerned whether than instancing happens when I add them in the editor or when I hit play.

I would think the Instanced property would do something resembling what I want, but it doesn’t seem to. DefaultToInstanced on the class itself seems to do nothing at all. Instanced on the array won’t let me set array elements to anything but None. Instanced + EditInlineNew only lets me add a blank UTeamDataAsset, although it works how I would expect otherwise.

My current janky solution is to not use any variety of Instanced or EditInlineNew and just replace each element with the return value from DuplicateObject, but surely there’s a better way. Anyone know what that way is?

Test notes below:



UCLASS(BlueprintType)
class TESTPROJECT_API UTeamDataAsset : public UDataAsset

    UPROPERTY(BlueprintReadWrite, EditAnywhere)
    TArray<UTeamDataAsset*> teams;


-can add TestTeamDataAsset
-edits original after hitting play



UCLASS(BlueprintType, DefaultToInstanced)
class TESTPROJECT_API UTeamDataAsset : public UDataAsset


-can add TestTeamDataAsset
-edits original after hitting play



UCLASS(BlueprintType)
class TESTPROJECT_API UTeamDataAsset : public UDataAsset

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Instanced)
    TArray<UTeamDataAsset*> teams;


-can add element to the array, but the only option is None.



UCLASS(BlueprintType, DefaultToInstanced, EditInlineNew)
class TESTPROJECT_API UTeamDataAsset : public UDataAsset

    UPROPERTY(BlueprintReadWrite, EditAnywhere)
    TArray<UTeamDataAsset*> teams;


-can add TestTeamDataAsset
-edits original after hitting play



UCLASS(BlueprintType, DefaultToInstanced)
class TESTPROJECT_API UTeamDataAsset : public UDataAsset

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Instanced)
    TArray<UTeamDataAsset*> teams;


-can add element to the array, but the only option is None.



UCLASS(BlueprintType, EditInlineNew)
class TESTPROJECT_API UTeamDataAsset : public UDataAsset

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Instanced)
    TArray<UTeamDataAsset*> teams;


-can add element to the array.
-can only set it to TeamDataAsset, not TestTeamDataAsset, meaning it is blank.
-can edit the TeamDataAsset and it behaves as you would expect (changes from the editor transfer to PIE, but not the other way around)



UCLASS(BlueprintType, DefaultToInstanced, EditInlineNew)
class TESTPROJECT_API UTeamDataAsset : public UDataAsset

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Instanced)
    TArray<UTeamDataAsset*> teams;


-can add element to the array.
-can only set it to TeamDataAsset, not TestTeamDataAsset, meaning it is blank.
-can edit the TeamDataAsset and it behaves as you would expect (changes from the editor transfer to PIE, but not the other way around)