Objects and Function Sets

Objects and function sets are always used together. They are separate which easily establishes ownership—objects are always owned by Maya, and function sets are always owned by you.

Function sets

Function sets are C++ classes which operate on objects. In the example, Building a curve using a plug-in, MFnNurbsCurve is a function set (the MFn prefix indicates this).

These two lines create a new curve.

MFnNurbsCurve curveFn;
MObject curve = curveFn.create( ... );

If you add a third line:

curve = curveFn.create( ... );

a second curve is created and the curve MObject now references the new curve. The first curve still exists—it simply is no longer referenced by the MObject handle.


The Maya API uses proxy objects to create new types of Maya objects. Proxies are objects that you create but Maya owns.

A common misunderstanding is that you can create new types of objects by deriving from an existing function set. For example, MFnNurbsSurface derives from MFnDagNode. You might conclude that if you derive MySurface from MFnDagNode and provide all the methods to operate on a special surface type, you would have added a new surface type to Maya. Unfortunately this doesn’t work. What you would have is simply a new function set which operates on existing objects using the new methods. Remember that function sets are entirely owned by you. Maya never sees or uses them; Maya only uses the objects underlying the MObject handle.


An interesting consequence of the separation of objects and function sets is that the API can operate in a typeless manner. For example:

MFnNurbsCurve curveFn;
MObject curve = curveFn.create( ... );
MFnNurbsSurface surface( curve );

This code creates a curve and passes it to a surface function set on which to operate. Since MFnNurbsSurface only operates on surface objects, the above example does not do anything, but you may not know it. The error checking code in the API checks for such erroneous initializations.

Function sets accept MObjects of any type and if they do not recognize them, ignores them and returns error values whenever you try to operate on them. See Error checking, MStatus class, and Error logging in this chapter.