Hi there,
I’m not 100% I understand what you’re aiming for, so correct me if I’m wrong. It looks like you’re trying to have a UDataAsset be optionally inline editable (that is, you can specify a template data asset to use in a blueprint, or you can decide to override the template values directly in the editor panel of the blueprint?).
If this is what you want, then something like the following setup might work for you. This will let you specify a standard data asset, but optionally override it with an inline version that you can change in the blueprint details panel. You could also add a copy constructor to the data asset if you wanted to copy over the template values on checking the override boolean flag in editor:
Edit: Sorry copy constructors can’t be made for UObjects. To create a new inline editable instance when the override Boolean is checked, that uses your specified data asset as a template, call the NewObject function with the template argument set to your specific data asset. Do this in PostEditChangeProperty when the override Boolean gets set to true.
An example data asset class:
UCLASS(BlueprintType, EditInlineNew)
class LIGHTINJECTCRASH_API USomeDataAssetBase : public UDataAsset
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite);
FVector SomeVec1;
UPROPERTY(EditAnywhere, BlueprintReadWrite);
FVector SomeVec2;
UPROPERTY(EditAnywhere, BlueprintReadWrite);
bool SomeBool;
};
Example Actor .h:
UCLASS(Blueprintable)
class GAME_API ASomeActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
ASomeActor(const FObjectInitializer& FObjectInitializer);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
bool OverrideDataAsset = false;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta=(EditCondition = “!OverrideDataAsset”))
TObjectPtr<USomeDataAssetBase> SomeDataAsset;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Instanced, meta = (EditCondition=“OverrideDataAsset”))
TObjectPtr<USomeDataAssetBase> SomeDataAssetOverride;
#if WITH_EDITOR
virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
#endif
private:
UPROPERTY()
TObjectPtr<USomeDataAssetBase> OriginalDataAsset;
};
in Actor .cpp:
#if WITH_EDITOR
void ASomeActor::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (OverrideDataAsset)
{
if (!OriginalDataAsset)
{
OriginalDataAsset = SomeDataAsset;
}
SomeDataAsset = SomeDataAssetOverride;
}
if (!OverrideDataAsset && SomeDataAsset == SomeDataAssetOverride)
{
SomeDataAsset = OriginalDataAsset;
OriginalDataAsset = nullptr;
}
}
#endif
Let me know if you had something else in mind though.
Regards,
Lance Chaney.