Values in ActorComponent properties with Instanced and EditInlineNew keywords are not saved

I have a weird problem when using a UPROPERTY with the Instanced keyword in a custom ActorComponent.
There are several similar questions already, but I couldn’t find one for this specific problem.

Steps to reproduce (with an empty C++ project):

  1. Create three UObjects with EditInlineNew, two of them inheriting from the first one.

    UCLASS(Abstract, BlueprintType, Blueprintable, EditInlineNew)
    class UCppTestObj : public UObject
    {
    	GENERATED_BODY()
    };
    
    UCLASS(BlueprintType, Blueprintable, EditInlineNew)
    class UCppTestObj1 : public UCppTestObj
    {
    	GENERATED_BODY()
    };
    
    UCLASS(BlueprintType, Blueprintable, EditInlineNew)
    class UCppTestObj2 : public UCppTestObj
    {
    	GENERATED_BODY()
    };
    
  2. Create an ActorComponent with a property marked as Instanced:

    UCLASS()
    class UCppTestComponent : public UActorComponent
    {
    	GENERATED_BODY()
    
    protected:
    	UPROPERTY(EditAnywhere, Instanced, Category = "Game")
    	class UCppTestObj* MyObj;
    };
    
  3. Create an actor with this component:

    UCLASS(Blueprintable, BlueprintType)
    class ACppTestActor : public AActor
    {
    	GENERATED_BODY()
    
    	ACppTestActor(const class FObjectInitializer& ObjectInitializer);
    
    protected:
    	UPROPERTY(VisibleAnywhere, Category = "Game")
    	class UCppTestComponent* TestComponent;
    };
    
    ACppTestActor::ACppTestActor(const class FObjectInitializer& ObjectInitializer)
    	: Super(ObjectInitializer)
    {
    	TestComponent = ObjectInitializer.CreateDefaultSubobject<UCppTestComponent>(this, "TestComponent");
    }
    
  4. Create Blueprint of ACppTestActor , set the property MyObj of the TestComponent to “Cpp Test Obj 1”.

  5. Place the actor in a map and change the property on the instance to “Cpp Test Obj 2”.

  6. Save the map, exit (or load another map) and load it again. The value on the placed actor will have returned to “Cpp Test Obj 1”.

Notes:

  • This has even weirder effects when the property in the component is a TArray, but I suspect it is the same underlying cause and this is the simplest example I could create.

  • When the component is placed inside a simple Actor Blueprint in the editor, the value cannot be changed at all on the instance.

  • When the property is placed directly in the actor instead of the component, everything works as expected (value can be changed and is saved correctly).

The functionality would be really useful to have, so I would be thankful for any tips in getting this to work.

Hey BStbck-

This is a known issue that has been repoted here: Unreal Engine Issues and Bug Tracker (UE-38871) . You can track the report’s status as the issue is reviewed by our development staff. Please be aware that this issue may not be prioritized or fixed soon.

Cheers

Hi ,

thanks for the info.
It might to worthwile to add a note to the issue that it also happens on single element properties instead of only for TArrays, though.

Regards
BStbck

I got a similar issue (I suspect the same root cause) when trying to set a default value for an Instanced property in the C++ constructor using CreateDefaultSubobject. When I changed the value of the property in a blueprint class, it wouldn’t be properly saved. Or rather, the property does get saved, but it is not loaded properly, or it is replaced by the default object after loading (I realised this when I commented out the CreateDefaultSubobject line after saving a blueprint with a modified property value and then it was loaded correctly).

Hi, We hope this Blueprint Class “EditInlinenNew” plugin (which no longer requires any C++ to use the EditInlinenNew feature) will help you.

The way I handle this is to create a blueprint class derived from that ActorComponent and add it to actor on blueprint, not in C++