: Documentation : Code Snippets

A Node Callback is a piece of code that is run each frame. You can create a custom callback for any node you add to the scene graph, and it is the recommended place to perform updates. To create a callback, simply subclass osg::NodeCallback and override the () operator.

class MyUpdateCallback : public osg::NodeCallback {

    virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) {

        // Add custom code here...

        traverse(node,nv);
    }
};

You then attach your callback to your node.

node->setUpdateCallback(new MyUpdateCallback());