Visual Scripting Crash Course | 3. Understanding Variables and Data Types

TikTok Effect House
17 Apr 202416:12

Summary

TLDRThis tutorial delves into the fundamentals of variables and data in visual scripting, illustrating how they serve as containers for diverse information. It explains the process of incorporating objects, properties, and assets as variables to manipulate object attributes and behaviors within a project. The video also covers creating custom variables, selecting appropriate data types, and choosing between single and array containers. Practical examples, such as image cycling on screen tap, are provided to solidify understanding. Additionally, tips on learning from templates and searching for variables are shared to enhance scripting skills.

Takeaways

  • 📦 **Variables as Containers**: Variables are like boxes that can hold different types of data, such as numbers, phrases, or lists.
  • 🔄 **Importing Data**: Objects, properties, and assets can be brought into the Visual Scripting Editor as variables to be used in scripts.
  • 🔧 **Modifying Attributes**: Nodes like 'Get component by type' allow you to access and modify object attributes like transform and mesh renderer.
  • 👀 **Visibility Control**: Variables can control object properties, such as visibility, using nodes like 'Set Visibility'.
  • 🔑 **Property Access**: Properties can be accessed and modified with 'Get' and 'Set' nodes, which peek inside or change the variable's content.
  • 💼 **Custom Variables**: Users can create custom variables to store and retrieve specific data needed for their scripts.
  • 🎛 **Variable Configuration**: Variables must be configured with the correct data type to ensure scripts function correctly and avoid errors.
  • 📊 **Data Types**: Common data types include Number, Boolean, String, Color, Vector (2D, 3D, 4D), Rect, Texture 2D, and Object.
  • 🗃️ **Container Types**: Variables can be single, holding one item, or array, which can store multiple items and be accessed by index.
  • 🖼️ **Real-World Application**: Variables can be used to create dynamic effects, such as image cycling with screen taps.
  • 📚 **Learning Through Templates**: Studying templates is a recommended way to learn how to effectively use variables in visual scripting.

Q & A

  • What is a variable in the context of visual scripting?

    -A variable in visual scripting is like a container that can hold different types of information such as numbers, phrases, or lists of data.

  • How can you bring objects from the hierarchy panel into the Visual Scripting Editor?

    -You can bring in objects from the hierarchy panel as variables by simply dragging them into the Visual Scripting Editor.

  • What is the purpose of the 'Get Component By Type' node?

    -The 'Get Component By Type' node is used to get the component attached to an object, such as its transform and mesh renderer.

  • How can you control the visibility of an object in visual scripting?

    -You can control the visibility of an object using the 'Set Visibility' node, which allows you to turn the object's visibility on and off.

  • What is the difference between 'Get' and 'Set' when dealing with variables?

    -'Get' is for retrieving the current value of a variable without changing it, while 'Set' is for modifying the value of a variable.

  • How can you add a new variable in the Visual Scripting Editor?

    -You can add a new variable by navigating to the Visual Scripting Editor, clicking on the 'My Items' button, and then clicking the 'Add' button next to 'Variables'.

  • What are the different data types you can configure for a variable?

    -Data types include Number, Boolean, String, Color, Vector2, Vector3, Vector4, Rect, Texture2D, and Seen Object.

  • What is the difference between a single container and an array container for a variable?

    -A single container holds one data item, while an array container can store multiple data items in the same variable.

  • How can you access an item from an array variable?

    -You can access an item from an array variable using the 'Get Item from Array' node and inputting the index of the item you want to retrieve.

  • What is a practical example of using variables in visual scripting?

    -A practical example is creating an image cycle that changes images upon screen taps, which involves storing textures in an array variable and accessing them in a loop or random order.

  • How can studying templates help in understanding the use of variables in visual scripting?

    -Studying templates allows you to see how variables are used in practice, understand their types, container types, and default values, and observe the effects of changing them.

Outlines

00:00

📚 Introduction to Variables and Data in Visual Scripting

This paragraph introduces the concept of variables and data in visual scripting. Variables are likened to containers that can hold different types of information such as numbers, phrases, or lists. The video explains how variables can be used to store and manipulate data within an effects project, including dragging objects from the hierarchy panel or properties from the Inspector panel into the Visual Scripting Editor. It also touches on the use of nodes like 'Get component by type' to access and modify object attributes, and 'Set visibility' to control object visibility. The importance of understanding the difference between getting and setting variables is emphasized, with a practical demonstration of making an object's hat invisible using a screen tab.

05:02

🔧 Customizing Variables in Visual Scripting

The second paragraph delves into the process of customizing variables within the Visual Scripting Editor. It explains how to create a new variable by navigating to the 'My Items' button and adjusting its details such as name, type, and default value. The paragraph also discusses the importance of selecting the correct data type for a variable to avoid errors and ensure proper script functionality. Common data types are explained, including number, boolean, string, color, vector (2D, 3D, 4D), rect, texture 2D, and seen object. Additionally, the distinction between single and array container types is clarified, with an example of how to use an array to store a series of colors.

10:06

🖼️ Using Variables for Practical Applications

This section illustrates how to apply variables in practical scenarios, such as creating an image cycle that changes upon screen tapping. It guides through the process of selecting an image object, using the 'Add Interaction' shortcut, and setting up a subgraph to cycle through textures. The paragraph explains how to create a variable to store multiple textures, set it up as an array, and input the textures into the variable. It also demonstrates how to use the 'Get variable' node to peek into the variable's value and test the image cycling functionality. The concept of looping, random, and shuffle orders for displaying images is introduced, providing a hands-on example of variable usage in visual scripting.

15:09

🎓 Learning Variables Through Templates and Quiz

The final paragraph encourages learning about variables by studying provided templates, which can showcase variable usage in various contexts. It suggests picking a template that aligns with one's interests and exploring the variables used within it. The video provides a tip on how to search for variables by name to understand their application within complex graphs. Additionally, a quiz is presented to test the viewer's understanding, asking which elements can be added as variables in a visual scripting project, with options ranging from numbers and strings to colors and textures.

Mindmap

Keywords

💡Variable

A variable in the context of the video is likened to a container that can hold different types of information such as numbers, phrases, or lists of data. Variables are fundamental to visual scripting as they allow for the storage and manipulation of data which is essential for scripting logic. For instance, dragging an object into the Visual Scripting Editor and using it as a variable enables modification of its attributes, such as using a 'Get Component By Type' node to access and manipulate the object's transform and mesh renderer.

💡Data

Data refers to the information that variables can hold in visual scripting. It can be of various types, including numerical values, text, or even complex structures like lists. The video emphasizes the importance of data as it is the raw material that variables manipulate to create dynamic effects. For example, dragging objects from the hierarchy panel into the Visual Scripting Editor allows users to work with their data as variables.

💡Visual Scripting

Visual Scripting is the main theme of the video, which is a method of programming where code is written using graphical nodes and connections instead of text. It allows for the creation of complex behaviors and effects by manipulating variables and data. The video delves into how variables and data types are used within visual scripting to control object properties and create interactive elements.

💡Node

A node, as mentioned in the video, is a function box that processes commands and data in visual scripting. Nodes are the building blocks of scripts in visual scripting, where each node performs a specific task. For example, the 'Get Component By Type' node is used to retrieve components attached to an object, allowing for further manipulation of its properties.

💡Hierarchy Panel

The Hierarchy Panel is a part of the user interface where objects in a scene are organized and managed. In the video, it is mentioned that objects can be dragged from the Hierarchy Panel into the Visual Scripting Editor to be used as variables, highlighting its role in accessing and utilizing objects within the scripting environment.

💡Inspector Panel

The Inspector Panel is discussed in the video as a place where properties of selected objects can be viewed and modified. It is used in conjunction with variables to get or set properties, such as position, which demonstrates how variables can interact with object properties in visual scripting.

💡Get/Set

The terms 'Get' and 'Set' are used in the video to describe two different operations on variables. 'Get' is used to retrieve the value of a variable without modifying it, akin to looking inside a box without changing its contents. 'Set', on the other hand, is used to change the value of a variable, similar to placing a new item into a box. The video provides examples of using 'Get Position' and 'Set Position' nodes to illustrate these concepts.

💡Asset Panel

The Asset Panel is mentioned as a place from where assets like images, textures, and materials can be dragged into the Visual Scripting Editor as variables. This panel is crucial for incorporating resources into the scripting environment, allowing them to be used in creating visual effects and interactions.

💡Data Type

Data types are categories of variables that define what kind of information they can store, such as numbers, booleans, strings, colors, vectors, etc. The video explains the importance of matching the correct data type to the variable to avoid errors and ensure that the script functions as intended. Understanding data types is essential for creating structured and effective scripts in visual scripting.

💡Container Type

Container Type refers to whether a variable holds a single item or an array of items. The video explains that a 'single' container can only hold one data item, which must be replaced if a new item is to be stored. In contrast, an 'array' container can store multiple items, which can be accessed by their index. This concept is demonstrated when setting up an array of textures for an image cycle effect.

💡Subgraph

A subgraph, as mentioned in the video, is a reusable piece of a visual script that encapsulates a specific behavior or functionality. The video describes how to use a subgraph for creating an image cycle effect by tapping on the screen, showcasing how subgraphs can simplify complex scripting tasks by abstracting them into reusable components.

Highlights

Variables are like containers for storing different types of information in visual scripting.

Objects, properties, and assets can be added as variables in the Visual Scripting Editor.

The Get component by type node is used to access components attached to an object.

Set visibility node allows toggling the visibility of an object.

Variables can be manipulated to control object properties like position.

Get position and set position nodes are used for accessing and modifying object positions.

Custom variables can be added to store and retrieve necessary data.

Variables can be customized in terms of name, type, and default value.

Data types are crucial for ensuring that variables store the correct kind of information.

Common data types in visual scripting include Number, Boolean, String, Color, Vector, Rect, Texture2D, and Object.

Container types for variables can be single or array, with arrays holding multiple data items.

Get item from array node is used to access specific items in an array variable.

Variables can be used to create dynamic effects like image cycling.

Templates can be studied to learn how variables are used in complex visual scripting projects.

Variables can be searched by name to understand their usage across different graphs.

The correct answer to the quiz is that assets from the asset panel, objects from the hierarchy panel, and properties from the Inspector panel can all be added as variables.

Transcripts

play00:04

Hi. Welcome back.

play00:05

Today we dive into the core elements that bring dynamic effects

play00:09

to life in visual scripting variables and data.

play00:14

Let's refresh our memories a bit.

play00:16

Remember, in our first video, we introduced the concept of a node

play00:21

as a kind of function box that passes around commands and data.

play00:25

Well, today we're going to expand on that

play00:29

by diving deeper into what data and variables really are.

play00:33

What is a variable?

play00:35

You can think of a variable as an incredible, amazing container.

play00:40

Just like you might use a physical box

play00:43

to store a watering can,

play00:46

a sun, and a package.

play00:49

In visual scripting, a variable acts just like this box.

play00:56

You can fill it up with different types of information

play00:59

such as a number, a phrase,

play01:04

or even a list of data.

play01:08

In the effects project,

play01:10

you can bring in objects from the hierarchy panel as variables

play01:14

by simply dragging them into the Visual Scripting Editor.

play01:20

You can also add properties

play01:23

from the Inspector panel as a variable

play01:26

and also asset images,

play01:30

textures, materials from the Assets

play01:35

panel into the Visual Scripting Editor as a variable,

play01:41

these elements fundamentally hold specific data

play01:45

that becomes instrumental to your scripting logic.

play01:49

For example, when dragging an object into the Visual Scripting Editor

play01:55

and transferring them into a node,

play01:58

it allows you to modify its attributes.

play02:02

We have a node called Get component by type,

play02:06

which will essentially get the component attached to this object.

play02:11

In this case its transform and mesh renderer for you to use.

play02:17

Also, you can dictate its behaviors.

play02:21

For example,

play02:22

you can use set visibility node to turn it on

play02:26

and off as you want.

play02:29

Let's give it a try.

play02:32

We will use screen Tab,

play02:34

our old friend, to control the visibility.

play02:38

This time.

play02:41

We want their hat invisible after the screen tab,

play02:44

so I will simply test it in the preview panel.

play02:49

Oh, look at that.

play02:50

It disappeared.

play02:53

Controlling the component and its property of an object

play02:56

as a variable is slightly different than the object itself.

play03:01

After selecting the object in the hierarchy panel.

play03:04

In this case, let's select left glass,

play03:08

and when you head over to the Inspector panel,

play03:12

find the property you want to modify

play03:14

by clicking the gray dot in front of the property.

play03:17

Name.

play03:19

Let's say we want to change the position,

play03:21

but you see there's two options that pop up here

play03:25

getting position and set position.

play03:29

What's the difference here.

play03:30

Getting a variable is like peeking inside the box

play03:33

to see what's there, but without changing anything.

play03:36

So a small tip for this is you can actually use

play03:39

the node peek to have a look at what's inside.

play03:43

And if you change the position to say

play03:46

ten zero zero, we'll see.

play03:49

The value in the peek node.

play03:51

Also, change straightforward, right?

play03:54

Setting a variable, on the other hand, is like placing

play03:58

a new item into our variable box, changing its content.

play04:02

Actually.

play04:03

So let's say we want the position of our object to get changed.

play04:07

After our screen tab we're using the node screen tab here.

play04:12

Link it over to the enter port of the set position.

play04:18

And we can simply just modify the

play04:20

value here to let's say five

play04:25

and y axis is five as well.

play04:28

So let's give it a try.

play04:31

We click on the preview panel and see

play04:33

the object actually moved over there.

play04:36

Just remember get is for peeking inside

play04:40

and set is for changing its value.

play04:43

Adding a customized variable.

play04:46

In addition to those preset variables

play04:49

you can also add new variables to store and retrieve the data you need.

play04:54

Start by navigating to the Visual Scripting Editor

play04:57

and click on the My Items button in the toolbar.

play05:01

From there, you'll want to click the add button

play05:05

next to variables in the My Item sidebar.

play05:08

You're now ready to customize your variable.

play05:11

Click on your newly created variable to view

play05:14

and adjust its details in the detail sidebar.

play05:18

Here, you can personalize settings such as the variables name,

play05:23

its type,

play05:24

and even its default value.

play05:28

This level of customization allows you to truly

play05:31

make your variables your own, but we are not done yet.

play05:35

To use your variable in the visual Scripting Editor,

play05:38

you need to click the Create Node Circle button next to your variables name.

play05:43

And here we need to decide whether we want to get or set the variable.

play05:48

There you have it.

play05:50

You are equipped to add and customize variables to suit your specific needs.

play05:55

In the Visual Scripting Editor,

play05:58

configure a variables data types.

play06:01

Okay, let's dive in a bit here.

play06:04

To configure a variable, you need to determine the data type.

play06:09

Go to the detailed side bar and find the type slot

play06:14

and click on the drop down button.

play06:17

It will show you a list of data type options,

play06:20

which essentially represent the kind of information

play06:23

your variable can store, and choosing the correct data type is essential.

play06:29

For instance, a number data type

play06:32

only stores numeric values,

play06:35

while a color data type is exclusively for color values.

play06:41

Making sure

play06:42

you match your data with the right data type is crucial.

play06:46

To avoid errors and ensure your script functions correctly.

play06:51

Let's break down some common data types you will use in visual scripting.

play06:56

Number

play06:57

can be an integer or float number with a decimal.

play07:02

Perfect for counting or indexing.

play07:06

Boolean is a data type

play07:08

that has only two possible values true or false,

play07:12

or much like a check box status

play07:16

check, or unchecked string

play07:20

is used for storing sequences of characters

play07:23

such as sentences or words.

play07:28

Colors manage color values,

play07:31

typically defined with RGB or hex

play07:35

vector two.

play07:37

Vector three

play07:39

and vector four.

play07:41

These represent positions or dimensions

play07:44

in 2D, 3D, and pseudo 4D

play07:48

spaces, respectively.

play07:51

Rect represents the dimensions of a rectangle

play07:54

in their 2D space defined by x, y.

play08:00

The width, and the height.

play08:02

Great for layout and interface design.

play08:05

Texture 2D pertains to a 2D texture

play08:09

often used for texture assets.

play08:12

You can set different assets to it as you want.

play08:16

The last one seen object.

play08:19

You'll find that storing and retrieving seen objects through variables

play08:23

is a very handy trick in game effect development.

play08:26

We will explain more later

play08:29

by understanding and correctly utilizing these different data types.

play08:34

You can create more structured and effective scripts.

play08:39

Configure a variables container type.

play08:42

When creating a variable,

play08:44

you also need to choose a type of container for your data.

play08:48

Go to the details sidebar and you will see from the dropdown menu

play08:53

that there are two options single or array.

play08:57

A single container means it holds one data item.

play09:01

It could be data of any type, number, or color.

play09:05

Essentially, if you want to store a new item,

play09:08

you have to replace the current one because it only has space for one.

play09:13

An array container is a bit more complex

play09:16

because it can store multiple data items in the same variable.

play09:21

For instance, let's say we want to have a box of colors

play09:25

by clicking on the add button under default value.

play09:29

You can set up the array the list of objects.

play09:32

Let's say we want to set the first item

play09:35

as red, the second item as green.

play09:41

And the third item as blue.

play09:43

These items are stored in an organized manner

play09:46

so you can access them by their position using

play09:50

git item from array node.

play09:54

You can simply just

play09:55

input this variable into this get item from array,

play10:01

and you can input the index of the item you'd like to retrieve.

play10:06

You may notice that zero is actually the starting point.

play10:10

It may seem counterintuitive, but this is how the computer world works.

play10:14

Zero is the starting point. And so on.

play10:17

Now we can have a peak adding the peak node,

play10:21

and you may notice that it shows up

play10:24

as a peak node for vector four, which is not what we want.

play10:28

We want to peak into the color

play10:31

because color is the variables data type.

play10:35

So we'll need to click on the drop down menu of the peak node.

play10:39

Now we will see that the first item

play10:42

is red exactly like what we stored there.

play10:45

An array is useful since it's an efficiently managed list or collection.

play10:50

You can store game objects, scores,

play10:53

and series of values and access them while using their order index.

play11:00

Demo okay.

play11:03

Let's examine how to use variables in real cases.

play11:07

Suppose we want to create an image cycle by tapping on the screen.

play11:11

The user can see different images popping up in order.

play11:15

First we need to select the image object from the hierarchy panel.

play11:20

Then let's go to the Inspector panel

play11:23

and we will use the Add Interaction shortcut.

play11:27

Scroll down and you will find a subgraph

play11:30

called.

play11:34

Click on it

play11:35

and it will open a subgraph that does exactly what we want.

play11:39

Now we need to input all of our textures into this slot.

play11:43

Image textures.

play11:45

We'll need a variable that can store all the textures we want to set.

play11:49

Head over to my items panel in the toolbar of the Visual

play11:53

Scripting Editor, and click on the add button near the variables section,

play12:00

and we will name our variable textures.

play12:04

Then go to the details sidebar.

play12:07

Since this is an image, we need to make sure that the variable box

play12:12

can hold images.

play12:14

In this case, we will select texture 2D.

play12:18

We want to put three images into it so it can't be a single container.

play12:23

It has to be an array.

play12:24

After setting up an array, click on the add button

play12:28

three times to create three boxes in this variable.

play12:33

By clicking on the default texture slot, you can swap it to the texture

play12:37

you prepared and I'll set it up like this.

play12:43

After setting everything up,

play12:45

we need to bring the variable into the Visual Scripting Editor.

play12:49

Since we don't want to change the value of the variable,

play12:52

we just want to peek into the variable value.

play12:56

So we're going to use git variable

play12:58

here after git variable.

play13:01

Link it over to these image textures.

play13:05

Now let's test it.

play13:07

Click on the preview button

play13:10

and you will see that the image changed

play13:14

because you set the order as looped.

play13:17

It will show in the exact order

play13:19

you set up this array.

play13:22

But if you change it to let's say random,

play13:27

it will just display a random image

play13:30

without following the index you set up in the array.

play13:35

You can also set it up as shuffle.

play13:38

Just give it a try.

play13:43

Pro tips use templates to learn variables.

play13:47

Variables are essential for creating complex effects and visual scripting.

play13:52

You can learn their usage by studying our templates.

play13:56

How do you learn from a template?

play13:58

Pick one template that resonates with your interests like the photo slideshow.

play14:03

Just remember, not all templates will use variables,

play14:06

but some of them will like multiple times.

play14:10

And when you open the template,

play14:12

you can simply head over to the Visual Scripting Editor.

play14:15

Click on the My Item sidebar and it will show you what variables get used there,

play14:20

and click on the variable in the list, and it will navigate

play14:24

you directly to the place where the variable gets used.

play14:28

And you can also have a look at the variable type,

play14:31

container type, and default value.

play14:34

And if you notice the variable is actually highlighted for you.

play14:39

So you can zoom in and out in order to understand

play14:42

how this particular variable gets used.

play14:46

And something very useful is to change the variable

play14:50

to observe the effect and apply your new knowledge to your projects.

play14:55

Another pro tip is you can actually search the variable by its name.

play15:00

So let's search upload count

play15:04

and you will

play15:05

see that there is an up and down button

play15:09

where you can navigate between all the different complex graphs.

play15:14

In order to see exactly how this variable gets used.

play15:19

And as you absorb in these functionalities and how they get used,

play15:23

you can get better at using them in your own projects.

play15:27

Happy exploration!

play15:31

Quiz time.

play15:33

Now before we end.

play15:34

Question which of the following can be added as a variable

play15:38

in a visual scripting project?

play15:40

A only numbers and strings be only objects from the asset panel.

play15:46

C assets from the asset panel.

play15:48

Objects from the hierarchy panel and properties from the Inspector panel.

play15:53

Audio only.

play15:54

Colors and textures.

play15:59

With this understanding, you're ready to create more complex

play16:03

and logical flows in your visual scripting projects.

play16:06

We'll explore this further in our next module.

Rate This

5.0 / 5 (0 votes)

相关标签
Visual ScriptingDynamic EffectsVariablesData TypesGame DevelopmentCoding TutorialAsset ManagementCustomizationInteractive DesignScripting Logic
您是否需要英文摘要?