How can I copy values from one UObject to another?

I want to copy all values from One UObject into another.
The Classes I want to perform this on have lots of variables, so manually setting each variable isnt practical.

Hey @somawheels. I don’t think there is a way to automatically do this. I believe you need to define a function in your UObject class so that you encapsulate all the copy behavior so that when you need to use it you can simply call this method and not have to rewrite all of the variable replication lines of code.

Hope this helps

I see. The reason I thought this might be possible is there is a DuplicateObject() function. This function makes a new UObject that is a copy of an other… however I do not want to create a new UObject for performance reasons and also because creating new UObjects is not threadsafe.

Yes, I am having the same problem. Since DuplicateObject exist there is no explanation for CopyObject to be missing. Please Epic add this feature.

You can use Unreal Reflection to do this for you (but it will only work for UProperties). I’m assuming Duplicate Object is doing something very similar. You can then make that into your own static utility function so you can use it anywhere.

Don’t forget, you could just look into the DuplicateObject code, copy it into your own code with some minor changes.