To do this from C++ is not the easiest thing. It’s not hard (tricky yes and possibly crashy), but there’s more code involved than a GetFoo() call.
First, you need to get the UClass for the object in question. Then you need to find the UProperty object of the variable, which contains the memory layout information for the class. Once you have that, you can use CopyCompleteValue() to copy the data from the instance of the object into an item of that type.
It can be done, but I recommend you look for an easier solution like an event or make the variable native