Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated to 3.5

...

  • Same Flow Graph can be used in multiple levels, but only exist in one location.
  • Modules can receive unique input values from their caller, allowing them to be very robust.
  • Modules can return unique output values to their callers, allowing them to be used in many different situations.
  • Modules are instancedcan be instanced (default behavior), meaning that multiple copies of the same module can be active simultaneously, but running with different inputs

Module Types

There are currently two supported module types.

  • Global: Modules which are used in multiple levels should be created as Global modules.
  • Level: Modules only used in a specific level should be created as Level modules.

Modules are saved in either of these two locations:

  • Global: ../GameSDK/Libs/FlowgraphModules
  • Level../GameSDK/Levels/<levelfolder>/FlowgraphModules

When loading a module, the system will first check the current level's FlowgraphModules folder. If the Module is not found there, it will then look in the Global FlowgraphModules folder. This gives you the potential to overwrite a Global Module with a Level-Specific Module if you wish.

Converting a Flow Graph to a Module

A Module is just a special flavor of a Flow Graph. This means ANY any Flow Graph can become a Module module with a few simple modifications made to it.

First create a module by selecting File -> New FG Module -> Global/Level... in the Flow Graph Editor:

Image RemovedImage Added

or right-click on the FG Modules item in the Flow Graph overview and choose New Global FG Module / New Level FG Module from  from the context menu:

Image Removed

Save the module in either of these two locations:

  • Game/Libs/FlowgraphModules/ (for a global module accessible in all levels).
  • Game/Levels/<levelfolder>/FlowgraphModules/ (for a level specific module).

Image Added

Your new module will appear in the Flow Graph overview:

Image RemovedImage Added

The new module will already contain two nodes: Module:Start_<YourModuleName> and Module:End_<YourModuleName>. These are specifically created for this module, and cannot be removed.

Start node outputNode Outputs:

  • Start - Called when Module is loaded: Called when the module was created by the caller node. Treat this like you would the Misc:Start Node.

End node inputs:

  • Success - call Game:Start node.
  • Update: Called when the caller node wants to pass new parameters or indicate that the internal state of the module should update/reset.
  • Cancel: Called when the caller node wants to cancel the module execution.

End Node Inputs:

  • Success: Call this to end the module and pass a 'success' status back to the caller node.
  • Cancel - call : Call this to end the module and pass a 'canceled' status back to the caller node.

Deleting a Module

If you want to delete a specific Module module you can right click on the Module module name in the FG Modules list.

Image RemovedImage Added

Note

If you delete a Module module it will also delete the saved XML file .

Saving a Module

To save your Flow Graph so that it can be used as a Module, all you need to do is bring up your Flow Graph in the Flow Graph Editor, and select Save from the File Menu. There are multiple locations where you should save the Flow Graph , depending on how you want to use it:

  • \Game\Libs\FlowgraphModules
    This is your Global Modules folder. Save your Module here if you want to use it in multiple levels.
  • \Game\Level\MyLevel\FlowgraphModules
    This is your Level Modules folder. Every Level can have their own Modules folder. Save your module here if you want to use it only in one particular level.

...

(Undo is not supported).

Calling a Module from Flow Graph

So now we have this Module ready to be used in our level. To call the Module, all you need to do is use the Call node specific to your module. It will be named Module:Call_<YourModuleName>:

Image RemovedImage Added

Inputs:

  • Call - : Call to load the Module module and begin its execution. If the module is already started it will trigger the update port of the Start node with updated parameters (only if not instanced).
  • Instanced: If set to 1 (default behavior) it will create a new independent instance of the module whenever you trigger the Call input port.
  • Cancel: Call to cancel this module (needs correct InstanceID if instanced).
  • InstanceID: InstanceID to identify a module instance. Can be -1 (default behavior) to create a new instance, otherwise it will update the given instance (only if instanced).

Outputs:

  • Done - Called when the Module OnCalled: Called when module was started (returns -1 if the module is not instanced).
  • Done: Called when the module returns with a Success success status.
  • Canceled - Called : Called when the Module module returns with a Fail fail status.

Custom Module Ports

You can also customize the inputs and outputs for each module, to pass extra data back and forth. To do so, select your module and use the Tools -> Edit Module menu option in the Flow Graph editor:

Image RemovedImage Added

This brings up a dialog which allows adding inputs and outputs:Image Removed

Image Added

Supported data types are:

  • Bool
  • EntityId
  • Int
  • Float
  • String
  • Vec3

Image Added

Clicking OK on this dialog will regenerate the module nodes (Start, End and Call) with the new inputs and outputs:

Image RemovedImage Added

Image RemovedImage Added

All inputs passed to the Call node will activate the corresponding outputs on the Start node, and similarly inputs to the End node will be passed back to the Call node when Success or Cancel are activated.

...

Code Block
titleCode/CryEngine/CryCommon/IFlowgraphModuleManager.h
borderStylesolid
#include "IFlowgraphModuleManager.h"
//...
IFlowgraphModuleManager* pModuleManager = gEnv->pFlowSystem->GetIModuleManager();

Calling a Module from C++

It is possible to call modules directly from C++.

Code Block
languagecpp
titleCalling a module from code
void CMyClass::MyModuleCallback(bool bSuccess, const TModuleParams& outputParams) 
{
   // do something with the output parameters 
}

void CMyClass::CallMyModule()
{
   IFlowGraphModuleManager* pModuleManager = gEnv->pFlowSystem->GetIModuleManager();
   if (const IFlowGraphModule* pModule = pModuleManager->GetModule(“MyModule”))
   {
      TModuleParams inputParams;
      //… add input parameters
      pModuleManager->CreateModuleInstance(pModule->GetId(), inputParams, functor(*this, &CMyClass::MyModuleCallback));
   }
}

 

Debugging a Module

In order to get an overview of all currently available Flow Graph Modules modules and/or see currently active module instances it is possible to use the following console variables:

  • fg_debugmodules 0/1/2 - 0: Disabled / 1: Shows a list of all currently available modules / 2: Shows a list of all currently available modules and active module instances
  • fg_debugmodules_filter "filterstring" - "filterstring" can be used to only show specific modules

  • Module: The name of the module.
  • ID: Internal module ID.
  • Num Instances: Number of currently active instances of the module.
  • Instance ID: Instance specific ID.
  • Caller Graph - Node: Flow Graph and Node ID of the Flow Graph who called the module. 
  • Type: Global or Level module.

 

Note

Grayed out modules are modules with no active instances.