Perhaps new duplication feature?

So I have recently been looking at Verse as it is coming to UE 6 and I have an idea not sure if it would be possible, but would be nice as a language feature. In UE C++ I have been saving objects information that have been spawned in and then later despawned in structs to then interact with the inventory. For C++ if I want to copy an object usually I have to write out a copy constructor and specify which member variables to copy if I wanted to say create a new class object and have it created with the same values stored in the previous. I did not know until recently that copy constructors can infer and copy variables without having to specify which variables to copy. Anyways in Verse it would be nice if when making a class you could maybe add something next to each variable and have the compiler then know which variables you would like duplicated or not. Some pseudo code below describing the process:

class classtemplate
{

(saved)int id = 1;
(saved)string name = “somestring”;
float isDamaged = false;

}

//classtemplate is how classa and classb are originally defined

Class classa
{

(saved)int id = 1;
(saved)string name = “newstring”;
float isDamaged = true;

}

Class classb; //unitialized

//save classb as a duplicate of classa
classb = duplicate(classa);

//classa and classb have separate memory allocations

//classb now after duplication looks like:

Class classb //still uninitialized, but saved information is set
{
(saved)int id = 1;
(saved)string name = “newstring”;
float isDamaged = false

}

so for the model it would be:

1.Allocate object
2.Fill fields
3.Run Initialization
4.Object is ready

The idea here is the ability to just create a unitialized object that is a copy of an initialized object with certain fields copied other fields that are not copied would be unitialized and or set to defaults. When the object is then initialized then the non saved fields will initialize and the saved fields will retain the saved values set.

I believe in C++ for UE structs are lightweight in comparison to classes because of reflection and that is why I would convert to a struct to save information and then later back into a class. As for Verse I don’t see an overhead difference just identity ref/value etc. so in this case maybe perhaps would be better to just add this so you can save unitialized objects that maintain saved copied information instead of going from spawning a class object to de-spawning and saving the information in a struct to then have to pass the information back into a new object to respawn this would just eliminate that and go from spawned object → saved info → new unspawned object. This also would eliminate the need to have to access each variable each time and set it to the value being copied.

For Verse pseudo code might be something like this:

Enemy := class:
(saved)Level : int = 1
(saved)Health : int = 100
Name : string = “ILostTheGame”

**SavedEnemy := duplicate(Enemy)
**

Thank you,

  • Jordan Savage