Skip to main content

Components in State Machine

TheA State Machine diagram is createdbuilt by combining core components such as “State”States and “Transition”.Transitions. TheseTypically, elementsa set of states are usedinterconnected through transitions to constructrepresent rulesthe that define a seriesflow of states, a series of possible inputs, and another state or transition to itself in response to the input. logic.

The following eight types of elements can be used as components of a State Machine in the Scene Composer. These cancomponents beare selectedavailable fromin the toolbar at the top of the State Machine Editor panel and placedcan onbe added to the diagram.

diagram
    using Initiala Statesimple Statedrag-and-drop Transition Subchart Entry/Exit Point History State Note Choice ViewState

    action.

    Initial State

    The Initial State is a special state that indicatesmarks the starting point of the stateState machine.Machine. ThereEvery isState alwaysMachine contains exactly one ofInitial theseState. in each state machine, and whenWhen the stateState machineMachine is executed, processing always startsbegins from this Initial State.

    drawing-4-1737960437.png

    State

    A State represents a specific logical state.condition within a State Machine. It indicatesreflects the current operation and conditionscontext withinof athe Statesystem. Machine, and specificSpecific actions can be performedexecuted when a State startsis entered or ends.exited:

    All
    actionsOnEntry associatedActions with- aExecuted when the State arestarts. executedOnExit sequentiallyActions - Executed when athe State startsends. (OnEntry) or ends (OnExit).

    These actions can be setconfigured in the propertiesProperties panelPanel or the Fusion editorEditor after selecting the target State.

    drawing-4-1737960451.png

    Transition

    A Transition represents a connection between two States and areis executed when specific conditions are met.Each Transitionstransition aggregateconsists of:

      Sender - The source that triggers the sendingEvent, object,which condition,in andturn action.initiates Ifthe Transition. Event - The event that initiates the Transition. Condition - A logical expression that must evaluate to true for the transition to occur. Actions - The operations executed when the condition evaluates to true, the action is executed.satisfied.

      Transitions are evaluated based onin the logical order defined.

      defined

      Inwithin addition,the ifState Machine. If multiple transitions areoriginate connected tofrom the same state,State, you canan setassign thepriorities priorityto ofdetermine thewhich transitions.transition should be executed first. For more details, see here.

      drawing-4-1737960481.pngdrawing-5-1767963927.png

      Subchart

      A Subchart is a structure that groups one or more States and Transitions.Transitions Theinto lowera single unit. In the diagram, the lower-right corner of a Subchart in the diagram is marked with an “S”S to distinguish it from a normal State.

      drawing-4-1737960507.png

      Subcharts can be connected to other States andor SubchartsSubcharts, onenabling the diagram,creation of flexible and modular flow structures. Double-clicking a Subchart opens its internal details, allowing you to createview flexibleand flowedit structures.its Double-clickingcontents.

      on

      Because a Subchart will display the details within it. As theySubcharts can be edited independently of the main diagram, they canare beideal usedfor to organizeorganizing complex logic ininto ansmaller, easy-to-understand way.sections.

      drawing-4-1737960576.png

      Entry/Exit Point

      A Entry PointPoints and a Exit PointPoints are pseudo-states that enable controlled entry into and exit to and from a Subchart.Subchart. They functionserve as clear starting and ending pointspositions for enteringnavigating a Subchart.

      By
      setting multiple Entry Points,Points: youAllow canthe Subchart to start a Subchart from different positions based on specific conditions. Multiple Entry Points can be defined to handle various scenarios. Exit Points: Provide controlled exits from the Subchart. Multiple Exit points can be configured to return to different states depending on the conditions.conditions Similarly, by setting multiple Exit Points, you can provide different exits depending on the conditions.
      drawing-4-1737960601.png

      Using Entry and Exit Points enables the creation of modular and condition-driven flows within complex State Machine diagrams.

      Example of Subchart Configuration Using Entry/Exit Point

      The following isexample shows a simple exampleconfiguration ofthat incorporates a configuration using a Subchart along with Entry Points and Entry/Exit Points.Points.

      drawing-4-1737694084.pngdrawing-5-1767970403.png

      In the figure above, the Subchart named "SubChartState_1" is placed onwithin the State Machine diagram.

        1. The state machine starts the transition fromat the Initial State onin the diagram,base anddiagram then(see movesleft tofigure above). From there it transitions into the Subchart state "SubChartState_1".
      and transitions to the Initial State inInside the Subchart (see diagramright 1figure above)., the flow begins at the SubChart's Initial State and proceeds to State_2. A mouse click causestriggers "Transition_5", moving the flow to State_3 within the Subchart. Another mouse click initiates a transition to State_1 ofvia the SubchartSubchart's (2Exit Point. And returns to the base diagram at State_1. A subsequent mouse click transitions to the base diagram's "State". With yet another mouse click, "Transition_3" in the abovebase figure).diagram Subsequently,is mousetriggered, click operation causes a sequential transitionleading to Statethe and ExitEntry Point of SubchartSubChartState_1 (3orange and 4frame in the aboveleft figure)diagram). As a result, the state machine transitions from Subchart to State_1 of the diagram (5 in the previous figure). Subsequent mouse clicks will transition to the diagram State (previous figure 6). A mouse click on this State triggers Transition_3, which is connected to the State, and thusThis re-enters the Subchart via the Entry Point (orange frame area in the above left diagram) again and returns to theState_3 State ininside the Subchart (above diagram 2)Subchart..

      History State

      A History State is a special State that iscan be placed withininside a Subchart,Subchart. andIts itpurpose hasis to remember the rolelast ofactive rememberingstate within the Subchart. When the flow transitions back into the Subchart, processing resumes from the state in which the Subchartthat was lastactive active.immediately Thisbefore makesexiting, itrather possiblethan to resume processingstarting from the StateSubchart's immediatelyInitial beforeState.

      exiting when transitioning back to the Subchart.

      Subcharts that contain a History State are marked with an “H”"H" in the top top-right corner.corner of the Subchart in the diagram.

      drawing-4-1737960626.png

      Example of History State Configuration

      The following isexample demonstrates a simple example of a configuration withwhere a History State is placed ininside a Subchart. This setup allows the Subchart.State Machine to resume from the last active state within the Subchart when re-entering, rather than starting from the Initial State.

      drawing-4-1737959821.png

      In the figure above, the State Machine diagram contains a Subchart "Media". withThe Subchart itself includes a History State isinstead placedof onan theInitial diagram.State.

      • The stateState machineMachine starts its transition fromat the Initial State onin the diagram,base diagram and then movestransitions to the Subchart "Media" (see the left diagram 1 above).
      • ItUpon entering the Subchart, it first passes through the History State (orange boxed area in the above figure)area) and then enters the State loop (red boxed area in the above figure)area), starting with Statethe "Bluetooth". state.
        • The state machine will remainremains in this Subchart as long as transitions between Bluetooth,Bluetooth, Radio,Radio, and USB are triggered.
        • When Transition_1 on(marked theas diagram (2 in the diagram above)figure) is triggered, thisthe Subchart will exit.
        exits. WhenAt this point, the History State records the last active state within the Subchart ends, History State remembers the State in the Subchart immediately before the exit. If the stateState machineMachine transitions againback to the Subchart "Media" via Transition_3 (Figuremarked as 3 above)in the figure), it transitionsre-enters the Subchart. Thanks to Subchartthe "Media" again.
          History State remembersState, the State of the last transitioned Subchart "Media". Therefore, the transition is restartedresumes from the last transitionedactive Statestate in(e.g. Bluetooth, Radio or USB) instead of starting from the SubchartInitial "Media". State.

          When exiting the Media state and transitioning to the Navigation state, the system executes not only the OnExit actions of the Media state is called,state, but also the OnExit actions of the last selectedactive meMediaMedia device state (Bluetooth/USB/Radio)e.g. Bluetooth, USB or Radio).

          When entering the Media statestate, asthe wellsystem asexecutes whenboth exitinglevels of OnEntry actions: the Media state,state's OnEnterOnEntry ofactions and the MediaOnEntry state as well as OnEnteractions of the stored most recently selected Media device state (Bluetooth/USB/Radio)e.g. willBluetooth, beUSB called.or Radio).

          SeeFor an example implementation that demonstrates the use of a History State within a Subchart, see State Machine SolutionSolution. for a sample state machine solution using History State.

          Note

          In athe State Machine Editor,Editor, you can add NoteNotes to the diagram to supplementprovide theadditional information.information, Thissuch helpsas youTODOs, caveats, implementation details or design considerations. Notes help improve clarity and make complex diagrams easier to visually organize the design contentunderstand and notes.maintain.

          drawing-4-1737960773.png

          Choice

          A Choice element allows you to branch Transitions.Transitions, Thisenabling makesthe itState easyMachine to editenter a specific state machines that define different behaviors based on the evaluation of multiple conditions. This feature simplifies the design and maintenance of complex logic where a set of conditions must be checked to determine the next state.

          Example of Choice Usage

          In the State Machine diagram below, the transition startsbegins fromat the Initial State on the diagram and transitionsproceeds to the Evaluate State.

          drawing-4-1737693957.png

            When the button is clicked in the Evaluate State, Transition"Transition" (marked as 1 in the above figure) is executed,triggered andby a mouse click, the transitionState Machine moves to the Choice element (orange frameorange-framed section in the abovefigure). figure),At wherethis point, the Transitiontransition branches.

            branches Inbased on the Transitionevaluated conditions:
              "Transition_too_high"Transition_too_high": (2 in the above figure), theThe processed value is checked to see if it exceedsagainst a specific threshold value.threshold.
              • If the condition is met:met Transition(value exceeds the threshold): The State Machine transition to "Red State" if the value is too largeState" (marked as 2 in the above figure).
              "Transition_okClicked":
                If the condition is not met:met If the (value is below the threshold,threshold): Transition_okClicked is executedexecuted, and athe transitionState Machine moves to the "Blue State" is madeState" (marked as 3 in the above figure).

                The priority of aan Exit Transition (Exit Transition) connected to a Choice element is the same as the normal Transition priority change procedure.

                By utilizing Choice,Choice elements, multiple conditions can be clearly organized within the stateState machine,Machine, making it easier to visually grasp the branching structure.structure easy to visualize. This makes it possible to design complex logic in a simple manner.

                ViewState

                ViewState is a dedicated State for controlling whether a specific View is shown or hidden within the state machine. It works with the View defined in the View Definition Editor and switches screens in sync with state transitions via the ActivateView action set in On Entry/On Exit Actions.

                You can create a ViewState either from the State Machine Editor toolbar or by dragging and dropping a View from Solution Explorer onto the State Machine Editor diagram.

                Create from a View

                To create a new ViewState from a View in Solution Explorer:

                1. In Solution Explorer, select any View.

                2. Drag the selected View and drop it onto a blank area of the State Machine Editor diagram.

                  • A new ViewState is placed on the diagram.

                3. Assign an ActivateView action to both On Entry Actions and On Exit Actions of the created ViewState.

                4. Configure the properties of the ActivateView action set on On Entry/On Exit Actions as described below.


                  Activate View
                  On Entry Actions True Specify the view that was dropped.
                  On Exit Actions False Specify the view that was dropped.
                  These settings establish the basic flow in which this View is displayed while this State is active.

                Place into an existing State/Subchart

                To place a View inside an existing State or Subchart:

                1. In Solution Explorer, select the target View.

                2. Drag the View from Solution Explorer onto the State Machine Editor diagram and drop it on the State or Subchart you want to use as the transition source.

                  • A new ViewState is placed inside the target State/Subchart.

                  • Transition from the containing State/Subchart to this ViewState is created automatically.

                  • Its Condition is automatically set to Jump to View.

                3. Assign an ActivateView action to both On Entry Actions and On Exit Actions of the ViewState.

                4. Configure the properties of the ActivateView action set on On Entry/On Exit Actions as described below.


                  Activate View
                  On Entry Actions True Specify the view that was dropped.
                  On Exit Actions False Specify the view that was dropped.
                  These settings let you configure a flow in which, when processing completes, the state machine transitions to the state that displays this View.