Download

How to copy properties from one UObject to another?

What is the best way to copy properties between 2 existing UObjects of the same class?

There is DuplicateObject macro, but it creates a new object. I also found EditorUtilities::CopyActorProperties, but it only works for Actors.

There is also UEngine::CopyPropertiesForUnrelatedObjects, which seems to do it, but it’s not really documented so I don’t know if it’s safe to use it.

Depends on what exactly you want to do…
In runtime there’s a way; in Editor for assets there’s other ways to do it.

Sorry, if forgot to say, it’s for the editor.

I have this tool released few days ago for Editor:

Pretty cool, downloaded!

But I need to do it in code.

I have an object that can be edited in a dialog window, and the user can then choose to confirm or cancel all the edits. So, I thought to create a copy of the edited object, show the standard property editor panel for the copy, then if the “ok” button is clicked copy all properties back to the original object. I can of course just copy them one by one, but then i need to update this copy every time i change the object.

The plugin has source included =]

Haha, right. Ok I will look there.

However, if your Object isn’t a Blueprint, you can’t;
Copying properties requires a GeneratedClass and access to Kismet Compiler.

CopyPropertiesForUnrelatedObjects kinda works for anything, except it doesn’t work for sub-objects for me. Or maybe I do something wrong.

I think I will just copy things manually, that’s more safe.

But, unless you’re talking about copying just values, as soon you close the Editor such object would reset to CDO instance, losing copied properties since new variables won’t be integrated to the base cpp (Archetype) class.

I’m still learning UE4 C++, but I think this one I did correctly, so it persists.

I have an object UBundle with an array of sub-objects UItem, which in turn has one AActror sub-object.
Each UBundle instance has its own .uasset file.

So, when I edit an UItem, I then call its Modify() method and the parent UBundle is marked as dirty in editor, then when I close the editor it will ask to save it.
I think this is correct, no?

Oh sure, if there’s an asset then the array size is serialized to the package.