Deep cloneing in UnityScript

I need deep clone of specific set of vars. So i thought i can use classes for this.

public var Slot1 : Module = new Module(None());

class Module
{
	var Name : String;
	var Icon : Texture;
	var Image : Texture;
	var Description : String;
	var Cost : int;
	var Prefab : GameObject;
	var Requirement : String;
	var ModuleType : int;
	function Module (mod : Module)
	{
		Name = mod.Name;
		Icon = mod.Icon;
		Image = mod.Image;
		Description = mod.Description;
		Cost = mod.Cost;
		Prefab = mod.Prefab;
		Requirement = mod.Requirement;
		ModuleType = mod.ModuleType;
	}
}
function None()
{
	var ModuleInfo : Module;
	ModuleInfo.Name = "None";
	ModuleInfo.Icon = Resources.Load("TestImage");
	ModuleInfo.Image = Resources.Load("TestImage");
	ModuleInfo.Description = "No module istalled in this slot";
	ModuleInfo.Cost = 0;
	ModuleInfo.ModuleType = 3;
	return ModuleInfo;
}

But i get an error in ModuleInfo.Name = “None”; line thet says:
NullReferenceException: Object reference not set to an instance of an object

I dont get it… Name obviously not null, what do i do wrong?

ModuleInfo is null on that line - you just declared the variable on the line above and didn’t set it to anything.

Found solution. I found article about values and refrances. Long story short, ModuleInfo is a refrance to Module class. Its not NEW object.
To correct this you need to create totaly new object. Just use constructor for thet.

class Module
{
	var Name : String;
	var Icon : Texture;
	var Image : Texture;
	var Description : String;
	var Cost : int;
	var Prefab : GameObject;
	var Requirement : String;
	var ModuleType : int;
	function Module (name : String, icon : Texture, image : Texture, description : String, cost : int, prefab : GameObject, requirement : String, moduleType : int)
	{
		Name = name;
		Icon = icon;
		Image = image;
		Description = description;
		Cost = cost;
		Prefab = prefab;
		Requirement = requirement;
		ModuleType = moduleType;
	}
}
function None() : Module
{
	var Name : String = "None";
	var Icon : Texture = Resources.Load("TestImage");
	var Image : Texture = Resources.Load("TestImage");
	var Description : String = "No module istalled in this slot";
	var Cost : int = 0;
	var Prefab : GameObject = null;
	var Requirement : String = null;
	var ModuleType : int = 3;
	return new Module (Name, Icon, Image, Description, Cost, Prefab, Requirement, ModuleType);
}