Patch Editor
Utility Patches
Multipeer Patches

Multipeer Patches Overview

Use multipeer patches to create AR effects that can be applied to more than one participant on a Messenger or Instagram video call. The multipeer logic enabled by these patches lets you build an effect that:

  • Runs separately on each participant’s device.
  • Can communicate with other instances of the effect, within the same call.

For example, you could create an effect where one participant tapping the screen triggers something else to happen in other instances of the effect, like changing the other participants’ background.

Available Participant Patches

There are five patches that you can use to create these kinds of effects: Pulse Pack, Multipeer Send, Multipeer Receive and Pulse Unpack and Throttle. You can find them in Spark AR Studio, in the Utility section of the Patch Menu.

Name Description
Pulse Pack

Pack and send information using a pulse signal. Must be connected to a Pulse patch.

Multipeer Send

Send a message on a specified multipeer channel. Use the Multipeer Receive patch to receive the messages sent from this patch.

Multipeer Receive

Receive a message on a specified multipeer channel. Use the Multipeer Send patch to send the messages this patch receives. Messages can only be sent between peers - you can’t send a message to yourself.

Pulse Unpack

Unpack information from a packed pulse signal. Use this patch with the Pulse Pack patch.

Throttle

Throttle a given event to a specified duration.

How the patches work

These patches let you package numerical, boolean, text or Vector2, 3, 4 data from one instance of an effect into a message to send to another instance, on a specified channel. You can have multiple message channels within the same effect. The message is made up of the data to input plus a key, which is a textual representation of the data being sent.

Sending the message

In the graph below, when the screen is tapped, the Pulse Pack patch packs information and sends it to the Multipeer Send patch. In this instance the information is someone’s name represented by the firstName key. GameTopic is specified in the Multipeer Send patch. This is the channel the message will be sent on.

Patch graph sending a message to the multipeer patch

For each additional piece of information you want to package into the message, connect a separate Pulse Pack. In the example graph below, we’ve added two Pulse Pack patches because we’re sending firstName data and position data on the mouth.

Patch graph sending first name and position data to the multipeer patch

Once the message is sent, it’s received by another instance of the effect via the Multipeer Receive patch. The Multipeer Send and Mutipeer Receive patches transmit data without a connecting cable, as long as the same Topic is specified.

Keep in mind that you can’t send a message to yourself. You need to have both Spark AR Player and Spark AR Desktop player open when building your effect, in order to test how different instances of your effect communicate.

Receiving the message

When the message is received you can unpack it with a Pulse Unpack patch and connect to further logic to trigger something in your effect. In the image below, the Pulse Unpack patch unpacks the message containing someone's name (Lucy) and sends this information to a Value patch.

Patch graph unpacking a message containing first name data

Testing

When you’re building your multi-peer effect, use the grid view in Spark AR Desktop Player to preview your effect running on a multi-participant video call.

Example

In the example below, we’re previewing an effect in Spark AR Desktop player, to test how it would appear on a video call with two participants. When Participant 1 blows a kiss, we see a heart appear on the device screen of Participant 2, and disappear again after 2 seconds.

We created this logic with the patch graphs below:

Patch graph that makes a heart appear when one participant blows a kiss

Sending the message

The top patch graph in the Kiss Event and Send Message box counts how many kisses are detected and sends this message on the SendHeartTopic channel.

We did this by connecting:

  • The Face output of faceTracker0 to the Kissing Face patch.
  • The Kissing Face patch to the Pulse patch.
  • The Turned On output of the Pulse patch to the Increase input of the Counter patch and the Event input of the Pulse Pack. We changed the data type in the Pulse Pack to a Number.
  • The Pulse Pack to the Multipeer Send patch.

Finally we entered:

  • KissCount as the Key in the Pulse Pack patch.
  • SendHeartTopic as the Topic input in the Multipeer Send patch.

Receiving the message and making the heart visible

The patch graph in the Message Received and Heart Visible box makes a heart appear each time this message is received. And then disappear again after 2 seconds.

We did this by connecting the Multipeer Receive patch to:

  • The Turn On Input of the Switch patch.
  • The Delay patch.
  • The Pulse Unpack patch.

We then entered:

  • KissCount in the Key input of the Pulse Unpack patch.
  • 2 in the Duration input of the Delay patch.

Finally, we connected:

  • The Delay patch to the Turn Off input in the Switch patch.
  • The Switch patch to a Visible property patch for Heart object.

The Pulse Unpack patch is not triggering anything to happen in the effect, it’s simply unpacking the message to retrieve a number for the last kiss count. You could connect this patch to other patches to make something else happen based on the number of kisses detected, adding more complexity to this effect.

Was this article helpful?