Create objects at run time (quadtree)

I’m trying to find what’s the best way to create dynamic objects at run time.
I have a heightmap class, that generates terrain geometry from a set of points.
Now I want this class to be able to store children (that will contain a more detailed representation of the terrain, for a LOD system).
So it will behave like a quadtree, each class has 4 children, each children have 4 children and so on.
I know how to create a class with children in C#, something like

public Class Heightmap : MonoBehaviour {
protected Heightmap[] children;
// other stuff here
}

However, I don’t know how to instantiante them in Unity, since every child will need a mesh renderer I suppose?
I’ve been searching and only found a way to instantiate prefabs (and this kind of geometry can’t be a prefab).

What I want is, when a Heightmap class is created, it automatically creates 4 children Heightmaps, and this continues recursively, until a certain number of subchildren are created. Each one has it own MeshRenderer component and its own geometry.
How to do this in Unity with C#?

Anyone?

Instantiate does take a GameObject but there is nothing stopping you from creating your own GameObjects at runtime.

// make a mesh
Mesh mesh = BuildMesh();  // whatever you do to make a Mesh

// make a GameObject container for Mesh
GameObject g = new GameObject(); // new GO at world origin

MeshFilter mf = g.AddComponent<MeshFilter>();
g.AddComponent<MeshRenderer>();
mf.mesh = mesh;

Hmm, are you sure that it’s possible?
I tried creating a new Heightmap at run time but got this error:
You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()

My code doesn’t create a MonoBehaviour with ‘new’. If you need to use a component, use AddComponent as I did here:

MeshFilter mf = g.AddComponent<MeshFilter>();
mf.mesh = mesh;

I understand the difference now, got it to work, thanks!

You know… you are completely describing rebuilding the Terrain class in Unity? I would use that instead. It is very versatile and will suit all of your needs.

Far from it. Holes, control over how the basemap is rendered, control over billboards, streaming, LOD methods, etc. It’s painful, but if you need any of these things you need to roll your own. Oh and the wonderfull foliage they introduced in 3.0 doesn’t work with it (shadows, shaders, wind).