Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 22 Next »

Flowgraph Module System

What is a Module

A Module is an exported Flowgraph that can be loaded and called from another Flowgraph at any point during the game session. Any Flowgraph can be converted to a Module simply by creating a new module in the Flowgraph Editor, and copying the Flowgraph contents to this new module.

The advantages of using Modules:

  • Same Flowgraph 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 instanced, meaning that multiple copies of the same module can be active simultaneously, but running with different inputs

Converting a Flowgraph to a Module

A Module is just a special flavor of a Flowgraph. This means ANY Flowgraph can become a Module with a few simple modifications made to it. First create a module by selecting File -> New FG Module... in the Flowgraph Editor:

or right-click on the FG Modules item in the Flowgraph overview and choose New FG Module from the context menu:

Save the module in either ../<YourGameFolder>/Libs/FlowgraphModules/ (for a global module accessible in all levels) or ../<YourGameFolder>/Levels/<levelfolder>/FlowgraphModules/ (for a level specific module). Your new module will appear in the Flowgraph overview:

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 output:

  • Start - Called when Module is loaded. Treat this like you would the Misc:Start Node.

End node inputs:

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

Deleting a Module

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

Note

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

Saving a Module

To save your Flowgraph so that it can be used as a Module, all you need to do is bring up your Flowgraph in the Flowgraph Editor, and select Save from the File Menu. There are multiple locations where you should save the Flowgraph, 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.

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.

Calling a Module from Flowgraph

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>:

Inputs:

  • Call - Call to load the Module and begin its execution.

Outputs:

  • Done - Called when the Module returns with a Success status.
  • Canceled - Called when the Module returns with a 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, use the Tools -> Edit Module menu option in the flowgraph editor:

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

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

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.

C++ Interface

To access the Flowgraph Module System from outside you can use the IFlowgraphModuleManager interface.

Code/CryEngine/CryCommon/IFlowgraphModuleManager.h
#include "IFlowgraphModuleManager.h"
//...
IFlowgraphModuleManager* pModuleManager = gEnv->pFlowSystem->GetIModuleManager();
  • No labels