How to pass a class without it being a pointer/reference?

function GiveEntityGun(ent : Entity, gunItemClass : ItemClass)
gunItemClass = new ItemClass();
gunItemClass.exist = true;
// … more stuff happens …

gunItemClass is not meant to stay as a reference. I need it to keep its values, but become its own instance. Unfortunately, this code wipes all its values.

Can anyone please help me? I haven’t been able to find the answer online yet.

You need to use a ‘copy constructor.’

class ItemClass {
  var myVar : float;

  function ItemClass() { myVar = 1; };

  function ItemClass( other : ItemClass ) {
    myVar = other.myVar;

Then later you can use var gic : ItemClass = new ItemClass( gunitemClass );