Parallel Activity Host nodes

Parallel Activity Host node can activate more than one of its child Activity nodes at a time. When you activate an Activity node, a Parallel Activity Host node brings that Activity to the front.

In a Parallel Activity Host node you can group Activity nodes, to show the groups in the same order that you defined in the node tree. When you activate an Activity node in a group, a Parallel Activity Host node brings to the front the Activity in that group. For example, this way you can implement the showing of critical messages, such as engine failure, in front of regular notifications, such as a phone call notification. In both groups a Parallel Activity Host node shows the Activity nodes in order of activation.

Using Parallel Activity Host nodes

To use a Parallel Activity Host node:

  1. In the main menu select Window > Activity Browser.

    ../../_images/activity-browser-main-menu.png
  2. In the Activity Browser click add-button and create a root Parallel Activity Host node.

    Kanzi Studio creates a Parallel Activity Host node in the RootPage node.

    ../../_images/activity-browser-create-root-pah.png ../../_images/node-tree-root-pah.png
  3. In the Activity Browser below the root Parallel Activity Host node click add-button to create an Activity node and create or assign a prefab to that Activity node.

    For example, create Activity nodes named Seatbelt, Tire Pressure, and Engine Failure. For each Activity node use the same name for the Activity prefab.

    Kanzi Studio creates Activity nodes, assigns them to the Parallel Activity Host node, and for each Activity node creates a prefab in the Prefabs.

    ../../_images/create-activity-and-prefab-seatbelt.png ../../_images/pah-seatbelt-tire-pressure-engine-failure-browser.png ../../_images/pah-seatbelt-tire-pressure-engine-failure.png
  4. Create a node with a trigger that you want to use to activate or deactivate an Activity node.

    For example, create a Toggle Button node and use the Toggle Button: Toggled On and Toggle Button: Toggled Off triggers.

    ../../_images/activate-project-toggle-button.png ../../_images/node-components-toggle-button.png
  5. In the Node Tree select the node that you created in the previous step, in the Node Components > Triggers press Alt and right-click the trigger that you want to use to activate an Activity node, select the Activate Activity action, and in the action set:

    • Target Item to the Parallel Activity Host node that contains the Activity node that you want to activate.

    • Activation Path to the path in the Parallel Activity Host node to the Activity node that you want to activate.

      If you nest Activity nodes in other types of nodes, include in the path only the ancestor Activity nodes.

      Tip

      To get the full path to an Activity node, in the Activity Browser right-click an Activity node and select Copy Activation Path. This command copies the entire path from the top-level Activity Host node to that Activity node.

      ../../_images/activity-browser-copy-activation-path.png
    ../../_images/add-activate-activity-action-toggle-button.png ../../_images/activate-activity-configure-parallel-activity.png
  6. In the Node Components > Triggers press Alt and right-click the trigger that you want to use to deactivate an Activity node, select the Deactivate Activity action, and in the action set:

    • Activation Path to the path in the Parallel Activity Host node to the Activity node that you want to deactivate.

      If you nest Activity nodes in other types of nodes, include in the path only the ancestor Activity nodes.

    • Target Item to the Parallel Activity Host node that contains the Activity node that you want to deactivate.

    ../../_images/add-deactivate-activity-action-toggle-button.png ../../_images/deactivate-activity-configure-parallel-activity.png

Activating Activity nodes

You can activate an Activity node in these ways:

Finding out whether an Activity node is active

To find out whether an Activity node is active:

  • Check the value of the Activity Status property for that Activity node.

  • Check the value of the Controller Property property in the Exclusive Activity Host node for that Activity node.

Activating an Activity node with the Activate Activity action

Use the Activate Activity action when:

  • The condition for activating an Activity is too complex to be expressed with the value of a property

  • You do not know in advance the number of Activity nodes in an Activity Host node

To activate an Activity node with the Activate Activity action:

  1. Create an Activity Host node with several Activity nodes the activation state of which you can control with the Controller Property.

    ../../_images/eah-media-navigation-phone.png ../../_images/eah-media-navigation-phone-activity-browser.png
  2. Create a node with a trigger that you want to use to activate an Activity node.

    For example, create a Button node and use the Button: Click trigger.

    ../../_images/activate-project-button.png ../../_images/node-components-button-click.png
  3. In the Node Tree select the node that you created in the previous step, in the Node Components > Triggers press Alt and right-click the trigger that you want to use to activate an Activity node, select Dispatch Message Action > Activate Activity action, and in the action set:

    • Target Item to the Activity Host node that contains the Activity node that you want to activate.

    • Activation Path to the path from the Activity Host node to the Activity node that you want to activate.

      If you nest Activity nodes in other types of nodes, include in the path only the ancestor Activity nodes.

      Tip

      To get the full path to an Activity node, in the Activity Browser right-click an Activity node and select Copy Activation Path. This command copies the entire path from the top-level Activity Host node to that Activity node.

      ../../_images/activity-browser-copy-activation-path.png
    ../../_images/add-activate-activity-action.png ../../_images/activate-activity-configure.png

Activating an Activity node with the Set Property action

Use the Set Property action to activate Activity nodes when the logic of your application relies on the value of the Controller Property property to activate an Activity node.

To activate an Activity node with the Set Property action:

  1. Create an Activity Host node with several Activity nodes the activation state of which you can control with the Controller Property.

    ../../_images/eah-media-navigation-phone.png ../../_images/eah-media-navigation-phone-activity-browser.png
  2. Create a node with a trigger that you want to use to activate an Activity node.

    For example, create a Button node and use the Button: Click trigger.

    ../../_images/activate-project-button.png ../../_images/node-components-button-click.png
  3. In the Node Tree select the node that you created in the previous step, in the Node Components > Triggers press Alt and right-click the trigger that you want to use to activate an Activity node, select the Set Property action, and in the action set:

    • Target Item to the Activity Host node that contains the Activity node that you want to activate.

    • Target Property to the property type that you set in the Activity Host in the Controller Property property.

    • Fixed Value to the value of the Controller Property property that you use in the Activity that you want to activate.

    ../../_images/add-set-property.png ../../_images/set-property-configure.png

Activating the next or previous Activity node

To activate the next or previous Activity node:

  1. Create an Activity Host node with several Activity nodes the activation state of which you can control with the Controller Property.

    ../../_images/eah-media-navigation-phone.png ../../_images/eah-media-navigation-phone-activity-browser.png
  2. Create a node with a trigger that you want to use to activate an Activity node.

    For example, create a Button node and use the Button: Click trigger.

    ../../_images/next-previous-project-button.png ../../_images/node-components-button-click.png
  3. In the Node Tree select the node that you created in the previous step, in the Node Components > Triggers press Alt and right-click the trigger that you want to use to activate an Activity node, select either Navigate To Next Activity or Navigate To Previous Activity action, and in the action set:

    • Target Item to the Activity Host node that contains the Activity nodes that you want to activate.

    • (Optional) If you want the Activity Host node to activate the first or last Activity node when you set off the trigger after you reach the last or first Activity node in that Activity Host node, set the Loop Activity property to enabled.

    ../../_images/add-next-activity-action.png ../../_images/next-activity-configure.png

Using the Activity nodes in the API

For details, see the Activity2D, Activity3D, ParallelActivityHost2D, and ParallelActivityHost3D classes in the Kanzi Engine API reference.