UnityScript Inheritance and Constructors

Hi Folks

Sorry to post a probably simply question, but I am getting the following compile error for my code, when I add a Class2 that inherits from Class1:

"BCE0024: The type ‘Class1’ does not have a visible constructor that matches the argument list ‘()’. "

I am presuming that the compiler checks that if an instance is created of Class2 which is called say Class2(9), that it will want to know that the parent class can also be instantiated with the same arguments. But I have two constructors with exactly the same argument list so what gives?

Cheers for help

Edit: OK, so overloading with a second constructor with no arguments does the trick. Is there some lesson I can take away from this? Why does the compiler think that constructor needs to be able to accept no arguments?

function Class1 ()
{
}

class Class1 extends MonoBehaviour

{

	function Class1( id : int )

	{

	}



}



class Class2 extends Class1

{

	function Class2( id : int )

	{

	}



}

Use ‘super’ to call the original constructor:

    function Class2(id : int ){
		super(id);  //calls the original constructor
    }

I briefly cover Unityscript inheritance in my scripting guide:

http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

Thanks Tony. I did actually read your guide prior to my post - however I didn’t realise that the call of the parent constructor within the child constructor was mandatory (can I humbly suggest this might be useful to state in your guide?)

After a bit more thought, I can now see that it is and why: if you don’t call a parent constructor within a child constructor, it calls the parent constructor with no arguments/parameters, and if there is no such constructor defined it gets the error.