Within Lens Studio (as well as most programming languages), we start counting through lists at 0. Connect your list of objects to the "Array" input and leave the "index" at 0. Let's go ahead and enable the first item in our list and then we'll create the loop.įirst we need to add a "Get Element" node so that we can access specific items in our array of objects. You may notice that none of our effects/objects are visible after our loop. Now, even if all your objects are enabled in the Objects Panel, none of them will be visible in the Preview Panel. Click on the "+ Add Value" button and choose all the objects you want to cycle through. Select the new object and add a script component in the Inspector panel and select the script graph. The "Body" trigger will trigger for each item in the array, and the "SceneObject" output is the current object in the list. Then connect the "Body" output of the Foreach to the triangle input of the "setEnabled" and the "SceneObject" output to the "SceneObject" input. Then plug your "SceneObject Array Input" node (which will be displaying "objects" or whichever name you chose) to the "array" input of the Foreach. The triangle inputs/outputs signify different triggers we want our lens turning on to trigger the loop. Take the "OnAwake" node and plug it into the triangle input of the "Foreach" node. Now that we have our nodes, let's connect them. While we're adding nodes, let's also add a "setEnabled" node (be sure to select the one for SceneObjects, there are multiple different setEnabled nodes). To cycle through our array of objects, we are going to use a "Foreach" node. The trickiest part might be knowing what to search for! An array is a list of data, in this case the various objects we want to cycle through. Let's start by adding a "SceneObject Array Input" and naming it "objects." You can add nodes by right-clicking in the graph editor and then searching for the node you want to add. If I forget to disable one of the objects, it doesn't matter because the script will take care of that. Why? I like to do it in the script because then I can enable/disable objects at will while working on the lens inside Lens Studio, but then when it is running on my device it will always work. We can do this manually by enabling/disabling items in the Objects Panel, but I like to do it within the script. Starting with a clean slateįor our tap to change effect to function properly, we need to make sure all our various objects except for the first one start out disabled. Then in the Resources Panel, all we need to do is create a Script Graph and then open up the Graph Editor. These can be post effects, color corrections, 3D objects, etc. In the Objects Panel we just need to make sure we have several objects we want to cycle through. You can preview an effect using this technique by clicking here or by scanning the snapcode below. And the best part is, the script is 100% reusable for other projects. Lens Studio does not have this feature built in, but we can set it up pretty easily with visual scripting. Letting someone tap to change the background or a post effect is pretty common in lenses.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |