UPROPERTY(EditAnywhere, BlueprintReadOnly, Instanced, meta=(ExposeOnSpawn) in ActorComponenet is not preserved

When using this:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Instanced, meta=(ExposedOnSpawn))
	class UGAAttributesBase* DefaultAttributes;

(UGAAttributeBase, have EditInlineNew in UCLASS())

in ActorComponenet, which is in turn DefaultSubobject in another object, the value of Property is not preserved and it is reseted every time. you click compile.

Update:
When component is added trough Blueprint Componenets Tab, I can create object instances trough exposed property and they do not disappear. It seems like problem is only occurring when component is added as part of C++ class and spawned as DefaultSubobject in constructor.

Bump.

And in case someone had problem with it, the easy workaround is to instead make:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced)
TSubclassOf MyClass;

And then just spawn it using ConstructObject<> in something like InitializeComponent()

It’s bit cumberstone, but it’s working (;.

Hi,

Could you provide some more information to help reproduce the issue you are describing?

  • What version of the Engine are you using?
  • Are you using the binary version installed by the Launcher, or did you build the Engine from source code?
  • Is this only happening in your project, or are you able to reproduce it in a new project?
  • What class does UGAAttributeBase derive from, and how is it set up?

Oh, I though it should be very easy to reproduce, so there are steps:

  1. I’m using source 4.6 version (but it should be also case with launcher version, as I haven’t made any changes to sources).
  2. It’s happening anywhere.

Actually here is plugin code. It’s super simple:

https://dl.dropboxusercontent.com/u/70400220/Unreal-questions/GameAttributes.zip

Update I actually discovered more cases where Instanced falls short here is how to reproduce it:

Create new Actor class (in code!) and new UObject class.

In new UObject class call UMyClass add something like this:

UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ExposeOnSpawn)
TSubclassOf SomeClass;

Also make sure that UObject have

UCLASS(Blueprintable, BlueprintType, DefaultToInstanced, EditInlineNew)

Then In Actor class add this:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced)
TArray> MyClassesArray;

Then for testing pruposes override BeginPlay in actor and add this code:

for(TSubclassOf<UMyClass> item : MyClassessArray)
{
      UMyClass* spawnedClass = ConstructObject<UMyClass>(item, this);
      int32 SomethingToStopBreakPoint = 1;
}

Now, start editor, look for our actor, create blueprint out it (don’t change anything in blueprint defaults!), and place it on level.
Here is first thing.

Add new elements to MyClassesArray. They should have properly expose SomeClass property. Now change it. And voila, it changed for all elements in array! I’m not sure if that intended behaviour, but certainly not expected.

Ok. Now add breakpoint somewhere in BeginPlay() of our actor code, and play from editor.

Look at spawnedClass, SomeClass property. It will be null even though we have set some classes in editor. Again not sure if that is intended, but certainly not expected.

Edit.

Prooblem with

UPROPERT(EditAnywhere, BlueprintReadWrite, Instanced)
USomething* property;

Not being properly saved in actor component is also present in recent 4.7 branch.

I recommend you not place any tags if you don’t know what they do. EditAnywhere and BlueprintReadOnly seem to me like conflicting tags so they may produce weird results. I don’t think you need any of the instanced tags too.

They are not conflicting. I want property to be editable in defaults or details, but I don’t want them be editable by blueprint graph (that’s why ReadOnly).

Instanced expose properties marked as meta=(ExposeOnSpawn) in Defaults/Details panel. When you select proper class. (;.

I am still having a little bit of trouble with this one. If I understand correctly, you have a custom UObject class that uses TSubclassOf a different class. Then you have a custom AActor class that contains an array of the UObject class? Are there any specific steps that you are taking when you reproduce this?

Oh html protection eaten up some <>.

Yes in custom UObject like MyObject there is custom uproperty TSubclassOf< Type > . The type is irrelevelant, the important part is the ExposeOnSpawn meta.
It actually can be any UPROPERTY() float, int, custom struct.

Then in Actor there is array of TSubclassOf< MyObject >, which EditAnywhere.

The problem is, when you change ExposeOnSpawn property in one the array elements, all subclasses have it changed.

Although it might be intended behaviour and it is not as breaking as the fact, that

UPROPERTY(EditAnywhere, meta=(ExposeOnSpawn))
UMyObject* MyObject;

Is not saved when used on ActorComponent and it always reset to null. If that worked, I probably would not have to use TSubclassOf in first place ;).

Hi,

Thank you for the additional information and clarification that you have provided. I was able to reproduce both issues that you described, and have submitted a report about each one to have them investigated further.

UE-7053 - Setting a value in an array of UObjects results in the value being set for all elements.
UE-7055 - The value of a UObject property contained within an ActorComponent is reset to None whenever a Blueprint derived from a class containing the ActorComponent is compiled.

I’m also facing this issue (UE-7055). Any update on its status?

To give some more info, the problem is not only within derived blueprints, but can also occur when simply adding an actor into a level.

Place an actor which contains a component with an ‘Instanced’ property of a UObject derived class TheBaseClass, which is itself defined with ‘EditInlineNew’. In the actor’s details panel, set the property to a new instance of some class derived from TheBaseClass.

This appears to work as expected so long as the component class does not initialize the object property with a default. However, if in the component constructor the property is initialized with a call to CreateDefaultSubobject(), then the following occurs:

a) If in the details panel the property was altered to something other than ‘None’, then when running it will be overwritten by the constructor default. On reloading the editor, the value in the details panel will also have been overwritten.
b) If in the details panel the property was set to ‘None’, then this is maintained as expected and the constructor default does not get used.

NOTE: Above tested with 4.6.1

It seems like the issue (at least for ActorComponenets) is resolved for latest 4.7 version from github/

Ok great. I downloaded 4.6 for starting out with UE, but I did clone the repo too so I guess it’s time to switch to 4.7. Thanks for updating!

We had that same issue, fixed in this pull request. It sounds like the problem you’re having: https://github.com/EpicGames/UnrealEngine/pull/6105