How to make a recursion with created objects

I have a main object which creates new objects and connects with spring joint to them. And i need this to keep going. I want new created object to create another object and connect. And this keeps going on. But I’ve no idea how to do it. Any help will be appreciated.

Write a method which Instantiates a new object of the given class and connects it to the current object with a joint. Then, in Start() function tell the object to call this method. This should work.

If you want to limit the number of iterations, you can tell this method to take two arguments, one will be max number of iterations and it will be passed on to all new objects. Another argument would be an int counting how many times a new object was created. It would be increased by 1 in the method before being passed on as an argument.

Cheers

PS If something’s unclear, tell me, I was writing this hurriedly.

So it would look something like this:

class Something {
	private int maxIterations;
	private int currentIterations;

	void Start ()
	{
		if (currentIterations < maxIterations )
			CreateNew (currentIterations+1, maxIterations);
	}

	void CreateNew (int curr, int max)
	{
		//here instantiate the new Something object, obj
		//here attach the joint to obj and this object, using the keyword "this"
		//obj.maxIterations=max;
		//obj.currentIterations = curr;
	}
}

I don’t know anything about joints, but if there’s a command that conjoins two things, you can use it above.

How can i say “connect to object that created you” in code?