You can use the Patch Editor to add logic and interactivity to your effects. In this guide, you'll learn to make something in your effect change - for example a color or animation - each time a user interacts with your effect.
For the examples in this guide, we're going to use a Screen Tap patch. This patch will detect the tap of someone's finger on the device's screen, and output a boolean signal. You could use any other patch that outputs a boolean signal - like a facial gesture recognition patch, or another interaction patch. To see what kind of signal a patch outputs, check the insert menu in the Patch Editor.
You can use the If Then Else and Switch patches to switch between 2 options in response to an interaction from the user. In this example, we'll use these patches to change the color of a material in the scene each time a tap is detected on the device screen.
Right-click in the Patch Editor, and select:
You'll also need a to create a consumer patch representing the property you want these patches to change. For this example:
If you select the If Then Else patch and expand the blue box at the bottom of the patch, you'll see it can output different types of data. Select Color.
If, for example, you were using these patches to switch between two animations, you'd select Animation Data instead.
Next to Then and Else, click the color symbols on the patch to choose new colors for the material.
Instead of adding these options to the patch itself, you could connect other patches to these ports. For example, animation playback controllers if you wanted to change an animation, or audio playback controllers to change a sound.
Your graph should look like this.
As a result of connecting these patches, each time the screen is tapped, a switch is turned on or off. When it's on, the material will take the color added next to Then in the If Then Else patch. When it's off, it'll change to the other color.
You can test this in the Simulator, by selecting Simulate Touch from the menu and clicking anywhere in the Simulator:
To count between more than 2 options in response to an interaction, you can use the Counter and Option Picker patches.
Right-click in the Patch Editor and select:
You'll also need a consumer patch representing the property in the scene object that you want to change. Like before, for this example we'll use the Diffuse Texture property in a material, to change the color if a material in the scene.
The Counter patch can be use to count through different options, which we'll set in the Option Picker patch.
You can use the ports and adjust the values in the Counter patch to count through options in different orders, or jump to a specific option.
The Option Picker can accept and output different data types - like Animation, boolean signals and color. For this example, select Color.
To set options in the Option Picker, click the value next to each port. For this example, set a different color in each one.
Connect the patches, so your graph looks like this:
Make sure the Maximum Count is set to match the number of options you've set in the Option Picker. We've set the Maximum Count to 4, to show 4 colors.
To show a random option in your effect, all you need to do is replace the Counter patch, with a Random patch. Make sure the End Value in the Random patch matches the number of options you've set in the Option Picker.
Make an effect respond to taps on a device screen.
Make something happen in your effect when someone taps on an object.