Instancing is the killer feature of the scene editor, and I finally got it working properly.

It’s often used to save memory, and speed up production by reusing elements. I’m not worried about memory on this project, and copying (which most editors support) would also achieve reuse. But what I really want to do is block out the scenes using placeholders, and fill in the details later.

The choice of what to instance is very flexible, because nodes can be grouped in any way in the hierarchy.

The interface is as standard as possible. I use cut/copy/paste, but there’s an extra option – copy ref. This is just like copying a shortcut in Windows. You paste it as normal but what you get is a link to the original node instead of a copy.

The tricky part was designing the behaviour of the nodes so that instancing would be useful. Separation of concerns is the key here. When I instance a node, I don’t want to instance its position; that would lead to two nodes overlapping. So there has to be a separate transform node. But I do want to instance the branch that sits below the transform. So that has to be a separate node as well.

And that’s why it didn’t work in my original code. A transform node needs to have sub-nodes, so I inherited from branch node. Big mistake. It doesn’t need to be a branch node, it just acts like one. In general, nodes are containers of their sub-nodes, and the branch part of a transform node is contained inside it. It still looks like one node in the interface.

The lesson, if there is one, is that wanting to acquire the behaviour of another class is not a reason to inherit from it. Inheritance is like chaining two objects together – you’d better be sure you never want one without the other.