Communicating between different graphs can be achieved in various ways. Two of the easiest ways are by utilizing Custom Graph Events or Signals.
Custom Graph Events involves the creation of a Custom Event node in the graph that we want to receive the event, and a Send Event node in the graph that we want to fire the said event from (these can also exist on the same graph if you want to, but Custom Functions might be better suited in this case).
A Custom Event (node) can be created through the “Events/Custom/Custom Event” from within the node browser. Such custom events can have none or one argument of any type. If you do not want any argument the “Custom Event” node needs to be used, but in case you require an argument, the generic version of the “Custom Event (T)” node has to used, with T being the type of the argument you want to have. (see also -> Generic Type Nodes). In the example below a “Custom Event (float)” is used.
Such Custom Events rely on a string-based name for the event. In most cases you will want to leave the “Target” empty (and thus Self), since in most cases you will want this node to be called when the event is sent to this (Self) graph owner. If you wanted to “catch” an event sent to another graph owner instead, you can change the “Target” to that other graph owner. Alternatively you can also utilize multiple targets if so required and as such catch the event when it is sent to either target graph owner specified.
To send an event, we need to use the Send Event node and similar to the above, we can choose to have no or one parameter. In this example the Send Event (float) is used, since our previously created Custom Event node expects a float and of course we have to set the Event Name to be exactly the same as the one we’ve previously set in the Custom Event node above. The “Target” input of the node should also point to the graph owner we want to send the event to. If the input is left “Self” then the event will be sent to this graph owner instead as expected.
Signals are and can be used very similar to Custom Graph Events illustrated above, however they do not rely on a string-based name but rather or a Signal Definition asset reference which has to be created beforehand. They also support multiple parameters in contrast to simple Custom Graph Events and in all respects are an alternative to normal Custom Graph Events.
The first thing that has to be done is to create a Signal Definition asset which is possible in the project tab and under “Create/ParadoxNotion/CanvasCore/Signal Definition”. A Signal Definition acts as a reference to a single event and also allows to define the parameters (name and type) that the event uses through the Signal Definition inspector. All types added in the Preferred Types Editor are supported as normal.
To check whether a Signal has been invoked, the Signal Callback event node has to be used. Within the inspector of the Signal Callback node, the already created Signal Definition asset needs to be assigned in the relevant inspector field. Once that is done (or when you hit the Refresh button), the node will change accordingly and populated with a value output for each parameter defined in the Signal Definition, each of which will hold the value of the Signal when it is invoked.
Similar to Custom Graph Events explained above, in most cases you will want to leave the Target empty and thus “Self”, which means that the event node will fire when the Signal is invoked with this (self) graph owner as the target. If you want to “catch” a Signal invoked with some other target, you can set the Target inspector field to the required target instead.
Similar to Custom Graph Events, you can choose to have a Single or even Multiple Targets. The Received, Receiver and Sender outputs work the same way as explained above for Custom Graph Events.
To invoke a Signal, the Invoke Signal node has to be used. Within the inspector of that node, the Signal Definition that we want to invoke needs to be assigned in the relevant inspector field. Once that is done (or when you hit the Refresh button), the node will change accordingly and populated with a value input in this case, for each parameter that the signal has defined.
Similar to Custom Graph Events, the Target is the object we want to invoke the Signal to and in most cases you simply have to set the Target to the graph owner that has the Signal Callback node. Alternatively, you can also choose to invoke the Signal globally by checking the Global option checkbox. Doing this will make it so that all Signal Callbacks that point to the same Signal Definition assigned here, will be fired regardless of target.