.. _ogn_tutorial_state:

Tutorial 18 - Node With Internal State
======================================

This node illustrates how you can use internal state information, so long as you inform OmniGraph that you are
doing so in order for it to make more intelligent execution scheduling decisions.

The advantage of using internal state data rather than state attributes is that the data can be in any structure
you choose, not just those supported by OmniGraph. The disadvantage is that being opaque, none of the generic UI
will be able to show information about that data.

OgnTutorialState.ogn
--------------------
The *.ogn* file containing the implementation of a node named "omni.graph.tutorials.State". Unlike Python nodes with
internal state the C++ nodes do not require and empty `"state"` section as the presence of state information is
inferred from the data members in the node implementation class (i.e. `mIncrementValue` in this node).

.. literalinclude:: OgnTutorialState.ogn
    :linenos:
    :language: json

OgnTutorialState.cpp
--------------------
The *.cpp* file contains the compute method and the internal state information used to run the algorithm.

By adding non-static class members to your node OmniGraph will know to instantiate a unique instance of your
node for every evaluation context, letting you use those members as state data. The data in the node will be
invisible to OmniGraph as a whole and will be persistent between evaluations of the node.

.. literalinclude:: OgnTutorialState.cpp
    :linenos:
    :language: cpp
