[{"data":1,"prerenderedAt":2059},["ShallowReactive",2],{"tutorial-2021-06-visual-scripting-107-collections-loops":3},{"tutorial":4,"series":322,"author":2048},{"id":5,"title":6,"author":7,"body":8,"category":302,"cover":303,"date":306,"description":307,"extension":308,"meta":309,"navigation":310,"path":311,"seo":312,"series":313,"stem":314,"tags":315,"youtube":318,"youtubeRange":319,"__hash__":320,"slug":321},"posts\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-107-collections-loops.md","Collections & Loops","danielle",{"type":9,"value":10,"toc":281},"minimark",[11,15,20,23,29,34,46,51,55,78,83,87,98,103,107,125,130,134,141,145,151,155,162,165,169,178,183,186,189,193,199,204,208,219,224,228,242,247,251,259,262,266,271,274],[12,13,14],"p",{},"Collections are groups of items. Unity’s Visual Scripting provides us two collection types List and Dictionary.",[16,17,19],"h2",{"id":18},"list","List",[12,21,22],{},"A list is a collection of objects sharing the same data type. The items stored in the list are sequentially ordered, meaning that the order in which items are added is maintained.",[24,25,28],"article-image",{"src":26,"alt":27},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-1.jpg","Unity Visual Scripting – Creating a List","\nCreating a List.\n",[30,31,33],"h3",{"id":32},"creating-a-list","Creating a List",[12,35,36,37,40,41,45],{},"In the Blackboard inspector, create a new variable; at the type field, write down ‘list’ and select which data type the list should store. We can now add as many Values as we like to be part of the list.",[38,39],"br",{},"\nWe can also create a list by code using the ",[42,43,44],"em",{},"Create List"," node.",[24,47,50],{"src":48,"alt":49},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-2.jpg","Unity Visual Scripting – List Add Item, List Insert Item and Set Item nodes","\nList Add Item, List Insert Item and Set Item nodes.\n",[30,52,54],{"id":53},"adding-items","Adding Items",[12,56,57,58,60,61,64,65,67,68,71,72,74,75,45],{},"A few nodes are available for adding items to the list.",[38,59],{},"\nWith the ",[42,62,63],{},"List Add Item"," node, we connect the list and the item we want to add. The item will be appended to the end of the list.",[38,66],{},"\nIf we want to add an item to a specific position in the list, we use the ",[42,69,70],{},"List Insert Item"," node. This node has a third input – Index, which is the intended position. Note that Index starts counting from 0.",[38,73],{},"\nTherefore the first item’s index will be 0, the second is 1, and so on...\nWe can also replace an item at a given index position with another using the ",[42,76,77],{},"Set Item",[24,79,82],{"src":80,"alt":81},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-3.jpg","Unity Visual Scripting – Remove At node","\nRemove At node.\n",[30,84,86],{"id":85},"removing-items","Removing Items",[12,88,89,90,93,94,97],{},"With the ",[42,91,92],{},"Remove At"," node, we can delete an item from the list using its position in the index.\nWe use the ",[42,95,96],{},"Remove"," node to delete a provided item with its value instead of its index.",[24,99,102],{"src":100,"alt":101},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-4.jpg","Unity Visual Scripting – Get Item, First Item and Last Item nodes","\nGet Item, First Item and Last Item nodes.\n",[30,104,106],{"id":105},"getting-items","Getting Items",[12,108,109,110,113,114,116,117,120,121,124],{},"The ",[42,111,112],{},"Get Item"," node, as its name suggests, retrieves the item stored at a given index.",[38,115],{},"\nWe can fetch the first and last items using the ",[42,118,119],{},"First Item"," and ",[42,122,123],{},"Last Item"," nodes.",[24,126,129],{"src":127,"alt":128},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-5.jpg","Unity Visual Scripting – Contains Item, Count Items and Clear nodes","\nContains Item, Count Items and Clear nodes.\n",[30,131,133],{"id":132},"item-exists","Item Exists?",[12,135,136,137,140],{},"We can ask whether or not an item exists in a list using the ",[42,138,139],{},"Contains Item"," node, providing it with a value.",[30,142,144],{"id":143},"counting","Counting",[12,146,147,148,45],{},"When we need to know how many items a list contains, we use the ",[42,149,150],{},"Count Items",[30,152,154],{"id":153},"list-clear","List Clear",[12,156,157,158,161],{},"Finally, the ",[42,159,160],{},"Clear"," node will remove all items from a list at once.",[163,164],"article-assets",{},[16,166,168],{"id":167},"dictionary","Dictionary",[12,170,171,172,174,175,177],{},"Another collection is the Dictionary, which allows us to map one value to another.",[38,173],{},"\nWhen we create a dictionary, we need to specify which data type for an item’s Key and another data type for its Value.",[38,176],{},"\nWhen adding an item to the dictionary, we specify what key will map to it.",[24,179,182],{"src":180,"alt":181},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-6.jpg","Unity Visual Scripting – Create Dictionary","\nCreate Dictionary.\n",[12,184,185],{},"For example, we may create a dictionary with a String for both the Key and the Value. Then, each item will have a person’s name as the key and the person’s home address for the value. We can then ask the dictionary whats the address for a given name is.",[12,187,188],{},"To managing dictionaries, we use nodes similar to those introduced for managing lists.",[16,190,192],{"id":191},"loops","Loops",[12,194,195,196,198],{},"Loops allow us to repeat a section of our script multiple times.",[38,197],{},"\nNote that all iterations happen right away and will only stop when the condition is reached.",[24,200,203],{"src":201,"alt":202},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-7.jpg","Unity Visual Scripting – While Loop node","\nWhile Loop node.\n",[30,205,207],{"id":206},"while-loop","While Loop",[12,209,109,210,212,213,215,216,218],{},[42,211,207],{}," node has a boolean Condition input and two Flow outputs: Body and Exit.\nThe node will execute the Body flow repeatedly until the condition turns from true to false. At this point, the node will run the Exit flow.",[38,214],{},"\nWhen can we use a ",[42,217,207],{},"? We may want an enemy to continue to chase the player as long as it’s seeing it. However, once the player is out of view, the chasing loop is halted.",[24,220,223],{"src":221,"alt":222},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-8.jpg","Unity Visual Scripting – For Loop node","\nFor Loop node.\n",[30,225,227],{"id":226},"for-loop","For Loop",[12,229,89,230,232,233,235,236,238,239,241],{},[42,231,227],{}," node, we can define how many repetitions the loop should go through.\nThis node uses an Index to count the loop’s current iteration.",[38,234],{},"\nThe First number is the index’s initial value, and the Last number is the index’s upper limit; we will only get up to the last number and quite the loop just before we reach it. The Step will define the amount to increment the index after each iteration.",[38,237],{},"\nAn example of using a ",[42,240,227],{}," is spawning a specific number of enemies next to our player , configuring each one with a different weapon based on the Index value.",[24,243,246],{"src":244,"alt":245},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvs-loops-and-collections-9.jpg","Unity Visual Scripting – For Each Loop and Break Loop nodes","\nFor Each Loop and Break Loop nodes.\n",[30,248,250],{"id":249},"for-each-loop","For Each Loop",[12,252,109,253,255,256,258],{},[42,254,250],{}," node iterates over a collection’s items. We pass in a list or a dictionary.\nThe Item output provides us with the loop’s current iteration item.",[38,257],{},"\nWe may use this node to go through a list of the game’s characters and move each one of them.\nWe can also connect Dictionaries to this node by toggling on the Dictionary option.",[260,261],"article-affiliate-group",{},[30,263,265],{"id":264},"break-loop","Break Loop",[12,267,89,268,270],{},[42,269,265],{}," node, we can exit a loop at any given time. Furthermore, we can use it for any loop by using it inside the Body flow.",[272,273],"hr",{},[12,275,276,277,280],{},"In the next part of this series, we will learn how to work and use ",[42,278,279],{},"GameObjects"," – our bridgfe for interfacing with Unity.",{"title":282,"searchDepth":283,"depth":283,"links":284},"",3,[285,295,296],{"id":18,"depth":286,"text":19,"children":287},2,[288,289,290,291,292,293,294],{"id":32,"depth":283,"text":33},{"id":53,"depth":283,"text":54},{"id":85,"depth":283,"text":86},{"id":105,"depth":283,"text":106},{"id":132,"depth":283,"text":133},{"id":143,"depth":283,"text":144},{"id":153,"depth":283,"text":154},{"id":167,"depth":286,"text":168},{"id":191,"depth":286,"text":192,"children":297},[298,299,300,301],{"id":206,"depth":283,"text":207},{"id":226,"depth":283,"text":227},{"id":249,"depth":283,"text":250},{"id":264,"depth":283,"text":265},"tutorial",{"480w":304,"960w":305},"\u002Fposts\u002F2021\u002F06-23_107\u002Fvisual-scripting-loops-and-collections-480w.jpg","\u002Fposts\u002F2021\u002F06-23_107\u002Fvisual-scripting-loops-and-collections-960w.jpg","2021-06-22","Using and lollections and looping over their items from the Unity Visual Scripting to repeat a section of our script multiple times.","md",{},true,"\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-107-collections-loops",{"title":6,"description":307},"2021-visual-scripting-foundations","posts\u002F2021\u002F06\u002Fvisual-scripting-107-collections-loops",[316,317],"unity","visual-scripting","JYkFm1Sc3v8","[object Object]","ApgqOsWmFPBxq293S5_9CJK8Ir5hX7J_nKPS-OuSY7g","visual-scripting-107-collections-loops",{"id":323,"title":324,"description":325,"extension":326,"hideParts":327,"meta":328,"shortTitle":329,"stem":330,"__hash__":331,"posts":332},"tutorials\u002Ftutorials\u002F2021-visual-scripting-foundations.yaml","Unity Visual Scripting Foundations","Unity’s Visual Scripting package, previously named Bolt,\u003Cbr>allows artists and non-coders to develop rich gameplay without writing code!","yaml",false,{},"Unity Visual Scripting","tutorials\u002F2021-visual-scripting-foundations","6V0Dsd5i3WvyjHXrA3yP-jkuwS8vokMfKtytR-awEcQ",[333,497,760,973,1202,1452,1642,1817],{"id":334,"title":335,"author":7,"body":336,"category":302,"cover":484,"date":487,"description":488,"extension":308,"meta":489,"navigation":310,"path":490,"seo":491,"series":313,"stem":492,"tags":493,"youtube":318,"youtubeRange":494,"__hash__":495,"slug":496},"posts\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-101-getting-started.md","Getting Started",{"type":9,"value":337,"toc":479},[338,348,351,356,358,362,383,392,397,400,404,422,427,441,443,447,453,458,467,474,476],[12,339,340,341,344,345,347],{},"Welcome to our Unity’s Visual Scripting ",[42,342,343],{},"(previously named Bolt)"," tutorial!",[38,346],{},"\nBy the end of the series, you will possess all the tools required to bring to life the games you always wished to make.",[12,349,350],{},"Even if you never coded before, the first steps may be a tad confusing; but trust me – if you stick with it, you’ll get there in no time!",[12,352,353],{},[42,354,355],{},"Unity 2021 and later comes with the visual scripting solution built-in!",[163,357],{},[16,359,361],{"id":360},"creating-a-script","Creating a Script",[12,363,364,365,368,369,372,373,376,377,379,380,382],{},"In a new empty GameObject, or for any existing one, we add a ",[42,366,367],{},"Script Machine"," component: in the ",[42,370,371],{},"Add Component"," menu, select ",[42,374,375],{},"Visual Scripting → Script Machine",".",[38,378],{},"\nThis component is responsible for running a script.",[38,381],{},"\nWe’ll discuss its options in later parts, but at this point, change the Source to Embed and click Edit Graph.",[12,384,385,386,388,389,376],{},"The Script Graph window should appear.",[38,387],{},"\nNote you can also open it through the menu ",[42,390,391],{},"Window → Visual Scripting → Visual Scripting Graph",[24,393,396],{"src":394,"alt":395},"\u002Fposts\u002F2021\u002F05-18\u002Fvs-getting-started-1.jpg","Unity Visual Scripting – Script Graph window","\nVisual Scripting Graph window.\n",[12,398,399],{},"In this window, we can view and edit our script, a graph with nodes and connections representing a flow of command we provide to the computer.",[16,401,403],{"id":402},"adding-nodes","Adding Nodes",[12,405,406,407,411,412,415,416,418,419,421],{},"We already have two nodes; to add new ones, we ",[408,409,410],"code",{},"right-click"," the grid will open the ",[42,413,414],{},"Fuzzy Finder",", which organizes the various nodes by categories.",[38,417],{},"\nIf we already know the node we are looking for or the component it belongs to – we can search for it.",[38,420],{},"\nWe can also open the Fuzzy Finder by dragging a line from a node’s port and releasing the mouse.",[24,423,426],{"src":424,"alt":425},"\u002Fposts\u002F2021\u002F05-18\u002Fvs-getting-started-2.jpg","Unity Visual Scripting – Fuzzy Finder","\nFuzzy Finder.\n",[12,428,429,430,432,433,436,437,440],{},"Right-clicking a node allows us to replace it, duplicate it, or delete it. ",[38,431],{},"\nHolding and dragging down while pressing ",[408,434,435],{},"Control"," on Windows or ",[408,438,439],{},"Command"," on Mac will create a group – a handy way for organizing graphs.",[260,442],{},[16,444,446],{"id":445},"composing-a-script-graph","Composing a Script Graph",[12,448,449,450,452],{},"We construct a graph by connecting one node’s output to another node’s input.",[38,451],{},"\nConnecting the green arrows will establish the order of execution for our graph to follow.",[454,455,457],"article-giphy",{"gif":456},"YwJ6thd2mQ4qc9Xh3T","\nConstructing a graph.\n",[12,459,109,460,463,464,466],{},[42,461,462],{},"Value"," ports are used to connect values.",[38,465],{},"\nEach value port has a Type that must be matched when connecting nodes. Nodes missing an input value will recolor their header orange.",[12,468,469,470,473],{},"If the ",[42,471,472],{},"Dim"," option is active, disconnected nodes will appear darker.",[272,475],{},[12,477,478],{},"In the following parts, we’ll go through the foundations of scripting, introduce the most commonly used nodes you will need to be familiar with, and walk through creating our first visual scripted games!",{"title":282,"searchDepth":283,"depth":283,"links":480},[481,482,483],{"id":360,"depth":286,"text":361},{"id":402,"depth":286,"text":403},{"id":445,"depth":286,"text":446},{"480w":485,"960w":486},"\u002Fposts\u002F2021\u002F05-18\u002Fvisual-scripting-getting-started-480w.jpg","\u002Fposts\u002F2021\u002F05-18\u002Fvisual-scripting-getting-started-960w.jpg","2021-05-18","Unity’s Visual Scripting package, previously named Bolt, allows artists and non-coders to develop rich gameplay without writing code!",{},"\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-101-getting-started",{"title":335,"description":488},"posts\u002F2021\u002F05\u002Fvisual-scripting-101-getting-started",[316,317],null,"qqy6G-phn4rPde_JLRdWtyA5l5tJIWTDC99HLmTLPfk","visual-scripting-101-getting-started",{"id":498,"title":499,"author":7,"body":500,"category":302,"cover":748,"date":751,"description":752,"extension":308,"meta":753,"navigation":310,"path":754,"seo":755,"series":313,"stem":756,"tags":757,"youtube":318,"youtubeRange":319,"__hash__":758,"slug":759},"posts\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-102-data-types.md","Data Types",{"type":9,"value":501,"toc":739},[502,508,511,516,520,551,572,574,577,582,586,601,606,610,619,624,628,654,659,663,695,697,701,704,722,726],[12,503,504,505,507],{},"In this article, we will discuss data types: nodes representing single pieces of information.",[38,506],{},"\nData is the core of every script; in fact, all that computers do is manipulate and pass data.",[12,509,510],{},"There are many data types available for us to use in Unity Visual Scripting, but we don’t need to be familiar with all of them; The following are the most common ones:",[24,512,515],{"src":513,"alt":514},"\u002Fposts\u002F2021\u002F05-20\u002Fvs-data-types-1.jpg","Unity Visual Scripting – Numbers data types","\nInteger and Float literals.\n",[16,517,519],{"id":518},"numbers","Numbers",[12,521,522,523,525,528,529,532,533,536,537,540,541,543,544,547,548,376],{},"We have two types for representing numbers:",[38,524],{},[42,526,527],{},"Integer"," is a data type of number values like ",[408,530,531],{},"6",", ",[408,534,535],{},"10",", and ",[408,538,539],{},"-9",", commonly used for counting or ordering.",[38,542],{},"\nIt can represent both positive and negative numbers, but not numbers with a fraction like ",[408,545,546],{},"1.5"," or ",[408,549,550],{},"3.14",[12,552,553,554,557,558,532,561,564,565,568,569,376],{},"To represent these numbers with a fraction, we have the ",[42,555,556],{},"Float"," data type like ",[408,559,560],{},"0.5",[408,562,563],{},"7.0",", or ",[408,566,567],{},"-2.4","; Primarily used for measuring. However, besides storing both positive and negative numbers, it’s not limited to fraction numbers only – it can also represent an integer-like value such as ",[408,570,571],{},"4.0",[163,573],{},[12,575,576],{},"We mentioned we use number types for counting or measuring. In addition, we can also use them for arithmetic operations like addition and division or even comparing whether, for example, one number is greater than another.",[24,578,581],{"src":579,"alt":580},"\u002Fposts\u002F2021\u002F05-20\u002Fvs-data-types-2.jpg","Unity Visual Scripting – Boolean data type","\nBoolean literal.\n",[16,583,585],{"id":584},"boolean","Boolean",[12,587,588,590,591,547,594,597,598,600],{},[42,589,585],{}," is a data type with only two possible values – either ",[408,592,593],{},"true",[408,595,596],{},"false",". It can represent an object state, like whether a door is open or closed.",[38,599],{},"\nAs we will later learn, we can leverage them to execute different sections of the Graph’s flow.",[24,602,605],{"src":603,"alt":604},"\u002Fposts\u002F2021\u002F05-20\u002Fvs-data-types-3.jpg","Unity Visual Scripting – String data type","\nString literal.\n",[16,607,609],{"id":608},"string","String",[12,611,612,613,615,616,618],{},"A ",[42,614,609],{}," is a variable-length text, a sequence of characters like a name or a message. It can contain letters, numbers, symbols, and even emojis.",[38,617],{},"\nWe can use it to print messages to the debug console or display dynamic text in the game’s UI.",[24,620,623],{"src":621,"alt":622},"\u002Fposts\u002F2021\u002F05-20\u002Fvs-data-types-4.jpg","Unity Visual Scripting – Enum data type","\nEnum literal.\n",[16,625,627],{"id":626},"enum","Enum",[12,629,630,632,633,636,637,640,641,532,644,532,647,536,650,653],{},[42,631,627],{},", short for ",[42,634,635],{},"Enumeration",", is a data type consisting of a predefined set of values. For example, we can have a ",[42,638,639],{},"Platform"," enum made of ",[408,642,643],{},"PC",[408,645,646],{},"Mobile",[408,648,649],{},"PlayStation",[408,651,652],{},"Xbox",". We will usually use them to specify a single value from the available options it defines.",[24,655,658],{"src":656,"alt":657},"\u002Fposts\u002F2021\u002F05-20\u002Fvs-data-types-5.jpg","Unity Visual Scripting – Vector 3 data type","\nVector 3 literal.\n",[16,660,662],{"id":661},"vector","Vector",[12,664,665,666,668,669,532,672,532,675,536,678,681,682,684,685,688,689,532,691,536,693,376],{},"Vectors are a group of 2, 3, or 4, Float values. It can represent a character’s position, speed of a moving object, the distance between objects, and more.",[38,667],{},"\nDepending on the vector type, we can access its float components through the ",[408,670,671],{},"X",[408,673,674],{},"Y",[408,676,677],{},"Z",[408,679,680],{},"W"," properties.",[38,683],{},"\nFor example, a ",[42,686,687],{},"Vector 3"," consists of three floats accessed through ",[408,690,671],{},[408,692,674],{},[408,694,677],{},[260,696],{},[16,698,700],{"id":699},"ports","Ports",[12,702,703],{},"Nodes may have input and output ports; each excepts or provide a value of a specific data type. We can distinguish the port’s data type by its icon.",[705,706,707,716],"ul",{},[708,709,710,713,714],"li",{},[42,711,712],{},"Primitive"," data types, like most of the types we discussed in this video, are represented with a circle – where each type is colored differently.",[38,715],{},[708,717,718,721],{},[42,719,720],{},"Object"," data types, which are data types composed of multiple data types, are represented with an illustrative icon. For instance, a Vector data type is displayed with colored arrows.",[16,723,725],{"id":724},"literals","Literals",[12,727,728,729,732,733,735,736,738],{},"Besides nodes’ ports, we can add a data type value in our script using a ",[42,730,731],{},"Literal",". In the ",[42,734,414],{},", we can search for the ",[408,737,731],{}," term of each data type to add it to the script and then pass it as an input to another node.",{"title":282,"searchDepth":283,"depth":283,"links":740},[741,742,743,744,745,746,747],{"id":518,"depth":286,"text":519},{"id":584,"depth":286,"text":585},{"id":608,"depth":286,"text":609},{"id":626,"depth":286,"text":627},{"id":661,"depth":286,"text":662},{"id":699,"depth":286,"text":700},{"id":724,"depth":286,"text":725},{"480w":749,"960w":750},"\u002Fposts\u002F2021\u002F05-20\u002Fvisual-scripting-data-types-480w.jpg","\u002Fposts\u002F2021\u002F05-20\u002Fvisual-scripting-data-types-960w.jpg","2021-05-20","We will get to know the common data types from the Unity Visual Scripting documentation, including Integer, Float, String, Bool, Vector, and more...",{},"\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-102-data-types",{"title":499,"description":752},"posts\u002F2021\u002F05\u002Fvisual-scripting-102-data-types",[316,317],"WTcXkdasUcfG48BO-nIPJyXv20bYMzKQN7gq5AYBaC0","visual-scripting-102-data-types",{"id":761,"title":762,"author":7,"body":763,"category":302,"cover":961,"date":964,"description":965,"extension":308,"meta":966,"navigation":310,"path":967,"seo":968,"series":313,"stem":969,"tags":970,"youtube":318,"youtubeRange":319,"__hash__":971,"slug":972},"posts\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-103-lifecycle-events.md","Lifecycle Events",{"type":9,"value":764,"toc":952},[765,772,778,783,793,800,802,805,810,814,819,824,834,838,847,852,861,863,868,872,883,888,892,903,908,912,920,925,929,934,938,943,945],[12,766,767,768,771],{},"In this article, we will get familiar with the ",[769,770,762],"strong",{},", nodes triggered by Unity that are usually the starting points of our visual script graphs.",[12,773,774,775,777],{},"Like any game engine, Unity runs our games by executing a giant loop, repeating over and over to create and update each frame.",[38,776],{},"\nWith Lifecycle Events, we can tap into the game loop stages and apply our custom behaviors. We can also react to various states of a game object.",[24,779,782],{"src":780,"alt":781},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-9.jpg","Unity Visual Scripting – GameObject Lifecycle","\nGameObject lifecycle events in a Visual Scripting graph.\n",[12,784,785,786,120,789,792],{},"There are many events, such as ",[42,787,788],{},"Input Events",[42,790,791],{},"Physics Events","; we’ll come to know them as this series progresses. But, for now, we will focus on the Lifecycle Events; those are the events executed during the object’s appearance in the game.",[12,794,795,796,799],{},"As you may notice, the ",[42,797,798],{},"Event Nodes"," are distinguished with a green strip.",[163,801],{},[12,803,804],{},"To help explain the differences between the Lifecycle events, I will use the Debug Log node. With this node, we can print messages to Unity’s Console window. For example, this Log will print “Hello” in the console.",[24,806,809],{"src":807,"alt":808},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-1.jpg","Unity Visual Scripting – Debug Log node","\nDebug Log node.\n",[16,811,813],{"id":812},"on-start","On Start",[12,815,109,816,818],{},[42,817,813],{}," event is called the first time an object appears in the game. This node is called only once for a given script graph.",[24,820,823],{"src":821,"alt":822},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-2.jpg","Unity Visual Scripting – On Start node","\nOn Start node.\n",[12,825,826,827,830,831,833],{},"For example, above is the ",[42,828,829],{},"Debug Log"," node connected to the ",[42,832,813],{}," event. Once we enter play mode, the game will print “Hello” to the console one time.",[16,835,837],{"id":836},"on-update","On Update",[12,839,840,841,843,844,846],{},"When it comes to rendering, a game is like an animation where each animation frame is generated on the go.",[38,842],{},"\nThe ",[42,845,837],{}," event runs for each frame that occurs while playing; It’s the beating heart of our game, allowing us to adapt to the player in real-time.",[24,848,851],{"src":849,"alt":850},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-3.jpg","Unity Visual Scripting – On Update node","\nOn Update node.\n",[12,853,854,855,857,858,860],{},"In this example, we connect the ",[42,856,829],{}," node to the ",[42,859,837],{}," event. Once we enter play mode, the game will print “Hello” to the console on every frame as long as we play.",[260,862],{},[24,864,867],{"src":865,"alt":866},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-4.jpg","Unity Visual Scripting – On Fixed Update node","\nOn Fixed Udpdate node.\n",[16,869,871],{"id":870},"on-fixed-update","On Fixed Update",[12,873,874,876,877,879,880],{},[42,875,871],{}," node is triggered 50 times a second in a constant interval. We use it instead of ",[42,878,837],{}," when interacting with physics. ",[42,881,882],{},"We will discuss Rigidbody and physics in a later video.",[24,884,887],{"src":885,"alt":886},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-5.jpg","Unity Visual Scripting – On Late Update node","\nOn Late Update node.\n",[16,889,891],{"id":890},"on-late-update","On Late Update",[12,893,109,894,896,897,899,900,902],{},[42,895,891],{}," node is similar to the Update event but is triggered after all Update and Fixed Update events in all scripts.",[38,898],{},"\nWe can use ",[42,901,891],{}," when we want a camera to follow a moving object powered by an Update event.",[24,904,907],{"src":905,"alt":906},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-6.jpg","Unity Visual Scripting – On Enable node","\nOn Enable node.\n",[16,909,911],{"id":910},"on-enable","On Enable",[12,913,914,916,917,919],{},[42,915,911],{}," will be triggered every time the object is activated.",[38,918],{},"\nFor example, this may be used when a level is loaded, a GameObject is dynamically instantiated or re-activating a previously hidden object.",[24,921,924],{"src":922,"alt":923},"\u002Fposts\u002F2021\u002F05-24\u002Fvs-lifecycle-events-8.jpg","Unity Visual Scripting – On Disable & On Destroy nodes","\nOn Disable & On Destroy nodes.\n",[16,926,928],{"id":927},"on-disable","On Disable",[12,930,931,933],{},[42,932,928],{}," will be triggered when the object is de-activated.",[16,935,937],{"id":936},"on-destroy","On Destroy",[12,939,940,942],{},[42,941,937],{}," will be triggered immediately before an object is deleted or removed entirely from the level.",[272,944],{},[12,946,947,948,951],{},"In the upcoming article, we will look into asking questions with ",[42,949,950],{},"Logic"," nodes, the first step towards more complex scripts.",{"title":282,"searchDepth":283,"depth":283,"links":953},[954,955,956,957,958,959,960],{"id":812,"depth":286,"text":813},{"id":836,"depth":286,"text":837},{"id":870,"depth":286,"text":871},{"id":890,"depth":286,"text":891},{"id":910,"depth":286,"text":911},{"id":927,"depth":286,"text":928},{"id":936,"depth":286,"text":937},{"480w":962,"960w":963},"\u002Fposts\u002F2021\u002F05-24\u002Fvisual-scripting-data-types-480w.jpg","\u002Fposts\u002F2021\u002F05-24\u002Fvisual-scripting-data-types-960w.jpg","2021-05-24","Overview of the lifecycle events nodes from the Unity Visual Scripting documentation, including Start, Update, Enable, Disable, and more...",{},"\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-103-lifecycle-events",{"title":762,"description":965},"posts\u002F2021\u002F05\u002Fvisual-scripting-103-lifecycle-events",[316,317],"K9bgxa7e1EC8Pngm9U-eRUUiZWFcxAowVythhd8Febw","visual-scripting-103-lifecycle-events",{"id":974,"title":975,"author":976,"body":977,"category":302,"cover":1190,"date":1193,"description":1194,"extension":308,"meta":1195,"navigation":310,"path":1196,"seo":1197,"series":313,"stem":1198,"tags":1199,"youtube":318,"youtubeRange":319,"__hash__":1200,"slug":1201},"posts\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-104-logic-composing.md","Logic Composing","nir",{"type":9,"value":978,"toc":1177},[979,988,999,1002,1004,1008,1011,1016,1020,1039,1044,1048,1065,1070,1074,1080,1082,1086,1089,1094,1098,1107,1112,1116,1128,1132,1140,1145,1149,1163,1169,1171],[12,980,981,982,984,985,987],{},"What makes games unique compared to other entertainment mediums is their ability to react and adapt to their consumer in real-time.",[38,983],{},"\nReacting to players’ actions dictates the game to be aware of those actions and the rest of the game’s state.",[38,986],{},"\nIn this article, we will learn how to compose logic for asking the game about the current state.",[12,989,990,991,993,994,124,996,998],{},"When writing scripts, we can ask questions about the players’ actions and the game state; after receiving answers, we can decide upon them, as we will see in a later video.",[38,992],{},"\nTo compose questions, Unity’s Visual Scripting offers us a handful of ",[42,995,950],{},[38,997],{},"\nEach Logic node provides a single output, a boolean; thus, this article is all about the art of true and false.",[12,1000,1001],{},"Let’s say our game features a car. We can ask whether it has gas, do we have its key, is it broken, etc.",[163,1003],{},[16,1005,1007],{"id":1006},"comparing-values","Comparing Values",[12,1009,1010],{},"The building blocks for asking questions are comparing one thing to another.",[24,1012,1015],{"src":1013,"alt":1014},"\u002Fposts\u002F2021\u002F05-26\u002Fvs-logic-composing-1.jpg","Unity Visual Scripting – Equal and Not Equal nodes","\nEqual and Not Equal nodes.\n",[30,1017,1019],{"id":1018},"equality","Equality",[12,1021,1022,1023,1025,1026,1028,1029,120,1032,1035,1036,1038],{},"The fundamental comparison type is asking whether one thing is the same as another.",[38,1024],{},"\nIn a car, if the remaining amount of gas in the tank is equal to 0 gallons, we are out of gas; therefore, the car can’t drive.",[38,1027],{},"\nIn a graph script, we have the ",[42,1030,1031],{},"Equal",[42,1033,1034],{},"Not Equal"," nodes; each receives two values and answers if they are the same.",[38,1037],{},"\nThose nodes accept any data type, including numbers, strings, booleans, vectors, and others...",[24,1040,1043],{"src":1041,"alt":1042},"\u002Fposts\u002F2021\u002F05-26\u002Fvs-logic-composing-2.jpg","Unity Visual Scripting – Less, Less or Equal, Greater and Greater or Equal nodes","\nLess, Less or Equal, Greater and Greater or Equal nodes.\n",[30,1045,1047],{"id":1046},"less-greater","Less & Greater",[12,1049,1050,1051,1053,1054,1056,1057,1060,1061,1064],{},"When we have two numbers, we can compare their values and ask whether one is greater than, or maybe less than, the other.",[38,1052],{},"\nIf the car’s speed is above 55 miles per hour, we are exceeding the speed limit.",[38,1055],{},"\nIn a script, we can use the ",[42,1058,1059],{},"Greater and Less"," nodes to compare numbers. We also have the ",[42,1062,1063],{},"Greater Or Equal"," node to ask if a value is at least some value. And the Less Or Equal node to ask if a value is at most some value.",[24,1066,1069],{"src":1067,"alt":1068},"\u002Fposts\u002F2021\u002F05-26\u002Fvs-logic-composing-3.jpg","Unity Visual Scripting – Comparison node","\nComparison node.\n",[30,1071,1073],{"id":1072},"comparison","Comparison",[12,1075,1076,1077,1079],{},"If we want to ask multiple questions upon the same values, we can use the ",[42,1078,1073],{}," node, which answers all questions at once.",[260,1081],{},[16,1083,1085],{"id":1084},"composing-logic","Composing Logic",[12,1087,1088],{},"Now that we have the basic building blocks, we can combine them into more complex questions.",[24,1090,1093],{"src":1091,"alt":1092},"\u002Fposts\u002F2021\u002F05-26\u002Fvs-logic-composing-4.jpg","Unity Visual Scripting – And node","\nAnd node.\n",[30,1095,1097],{"id":1096},"and","And",[12,1099,1100,1101,1103,1104,1106],{},"If a character owns a car And has a key, it can drive the car.",[38,1102],{},"\nWe use the ",[42,1105,1097],{}," node to combine two questions, concluding if the answer to both is true.",[24,1108,1111],{"src":1109,"alt":1110},"\u002Fposts\u002F2021\u002F05-26\u002Fvs-logic-composing-5.jpg","Unity Visual Scripting – Or and Exclusive Or nodes","\nOr and Exclusive Or nodes.\n",[30,1113,1115],{"id":1114},"or","Or",[12,1117,1118,1119,1121,1122,1124,1125,1127],{},"If a car is out of gas Or has a malefaction, it can’t continue driving.",[38,1120],{},"\nWe can use the ",[42,1123,1115],{}," node to ask if either of the answers is true.",[38,1126],{},"\nOne thing to note is that when we say either question is true, we don’t mean that only one can be true. If we do want to limit only one of the questions to be true, we have another node to accomplish it.",[30,1129,1131],{"id":1130},"exclusive-or","Exclusive Or",[12,1133,1134,1135,1103,1137,1139],{},"Even if two characters own keys to the same car, it can only have one driver at once.",[38,1136],{},[42,1138,1131],{}," node to ask whether one and only one of the questions is true.",[24,1141,1144],{"src":1142,"alt":1143},"\u002Fposts\u002F2021\u002F05-26\u002Fvs-logic-composing-6.jpg","Unity Visual Scripting – Negate node","\nNegate node.\n",[30,1146,1148],{"id":1147},"negate","Negate",[12,1150,1151,1152,1154,1155,1157,1158,1160,1161,45],{},"As stated before, all of the nodes we discussed in this video result in a boolean value. We use the ",[42,1153,1148],{}," node to convert a positive boolean into a negative and vice-versa.",[38,1156],{},"\nFor example, the ",[42,1159,1034],{}," node is just a shortcut for negating the ",[42,1162,1031],{},[12,1164,1165,1166,1168],{},"We can combine multiple questions to ask even more complex questions. In fact, the ",[42,1167,1131],{}," node is an example for composing two questions.",[272,1170],{},[12,1172,1173,1174,1176],{},"Now that we know how to ask questions and compose them into more complex queries, we can move on to make decisions based on the answers.",[38,1175],{},"\nMore about it in the following article...",{"title":282,"searchDepth":283,"depth":283,"links":1178},[1179,1184],{"id":1006,"depth":286,"text":1007,"children":1180},[1181,1182,1183],{"id":1018,"depth":283,"text":1019},{"id":1046,"depth":283,"text":1047},{"id":1072,"depth":283,"text":1073},{"id":1084,"depth":286,"text":1085,"children":1185},[1186,1187,1188,1189],{"id":1096,"depth":283,"text":1097},{"id":1114,"depth":283,"text":1115},{"id":1130,"depth":283,"text":1131},{"id":1147,"depth":283,"text":1148},{"480w":1191,"960w":1192},"\u002Fposts\u002F2021\u002F05-26\u002Fvisual-scripting-logic-composing-480w.jpg","\u002Fposts\u002F2021\u002F05-26\u002Fvisual-scripting-logic-composing-960w.jpg","2021-05-26","Using the Logic nodes from the Unity Visual Scripting to composing complex questions, including And, Or, Equal, Greater, Leaser, and more...",{},"\u002Fposts\u002F2021\u002F05\u002Fvisual-scripting-104-logic-composing",{"title":975,"description":1194},"posts\u002F2021\u002F05\u002Fvisual-scripting-104-logic-composing",[316,317],"zLZ5PWDtmz8q3sVY3ALXq1b33_uaHJ55kmTTQ9QcrHQ","visual-scripting-104-logic-composing",{"id":1203,"title":1204,"author":976,"body":1205,"category":302,"cover":1440,"date":1443,"description":1444,"extension":308,"meta":1445,"navigation":310,"path":1446,"seo":1447,"series":313,"stem":1448,"tags":1449,"youtube":318,"youtubeRange":319,"__hash__":1450,"slug":1451},"posts\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-105-control-flow.md","Control Flow",{"type":9,"value":1206,"toc":1432},[1207,1213,1219,1221,1227,1232,1238,1247,1252,1256,1270,1275,1279,1308,1313,1317,1351,1356,1360,1372,1374,1384,1389,1393,1409,1414,1418,1427,1429],[12,1208,1209,1210,1212],{},"The Control Flow nodes, together with the Logic nodes, are the heart of coding.",[38,1211],{},"\nThey are used for decision-making, guiding a Script Graph on dynamically executing gameplay based on the game’s current state.",[12,1214,1215,1216,1218],{},"When we speak about control flow in Visual Scripting, we refer to how our scripts are executed: when different actions are performed and in what order.",[38,1217],{},"\nWe previously got to know data types and that nodes have inputs and outputs of data values. We also briefly mentioned that nodes feature green arrows – each arrow is a Flow.",[163,1220],{},[12,1222,1223,1224,1226],{},"When we connect an output Flow into an input Flow, we tell the Script Graph that after performing a node, it should move on and perform the connected node.",[38,1225],{},"\nWe now know the two types of connections in our Script Graph, the Control Flow of execution order and the Data Flow of passing values around. The two flows are not dependent; a node can be used without the Control Flow; we can also pass the Data Flow to one node and the Control Flow to another node.",[24,1228,1231],{"src":1229,"alt":1230},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvs-control-flow-1.jpg","Unity Visual Scripting – Control Flow and Data Flow","\nControl Flow and Data Flow.\n",[12,1233,1234,1235,1237],{},"We previously learned how Events are the starting points of Script Graphs; therefore, they feature only an output Flow.",[38,1236],{},"\nThey allow us to react to the players’ actions, and we can utilize the them to update our response to the player’s actions dynamically while taking the game’s state into account.",[12,1239,1240,1241,1243,1244,1246],{},"But first, let’s ask: when do we need dynamic decision-making in our scripts?",[38,1242],{},"\nLet’s say we want our character to unlock a door with a key. We only want the door to open when the character is holding the key.",[38,1245],{},"\nIn this scenario, we have a condition, and we want to behave differently depending on the condition’s state: If the character lacks a key, the condition is not fulfilled; otherwise, the condition is met.",[24,1248,1251],{"src":1249,"alt":1250},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvs-control-flow-2.jpg","Unity Visual Scripting – If node","\nIf node.\n",[16,1253,1255],{"id":1254},"if","If",[12,1257,109,1258,1260,1261,1263,1264,1266,1267,1269],{},[42,1259,1255],{}," node uses a boolean condition to determine which of two output flows to execute. When the condition is true, it will do something; otherwise, it will do something else.",[38,1262],{},"\nThis node has two inputs, a Flow and a Boolean. It also has two Flow outputs.",[38,1265],{},"\nThis may be the first node you encounter that consists of more than one output Flow.",[38,1268],{},"\nThe Control Flow will continue to only one of the branches; according to the input condition, the node chooses a branch – one branch for a True value and another for a False value.",[24,1271,1274],{"src":1272,"alt":1273},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvs-control-flow-3.jpg","Unity Visual Scripting – Switch nodes","\nSwitch nodes.\n",[16,1276,1278],{"id":1277},"switch","Switch",[12,1280,109,1281,1283,1284,1286,1287,1289,1290,1292,1293,1296,1297,1299,1300,1302,1303,843,1305,1307],{},[42,1282,1278],{}," node is similar to the If node but uses a value input instead of a boolean condition. As a result, this node can have more than just two branches of Flow outputs.",[38,1285],{},"\nWhen we select a ",[42,1288,1278],{}," node, we can add, edit, and remove options in the Graph Inspector – each option we add will create an additional output Flow for the node.",[38,1291],{},"\nFor example, you can use an ",[42,1294,1295],{},"Integer Switch"," node that executes a different Flow for each value of 1, 5, and 21.",[38,1298],{},"\nMoreover, the ",[42,1301,1278],{}," node has a Default Flow output; it is used when the input value doesn’t match any given option.",[38,1304],{},[42,1306,1278],{}," nodes come in three data type flavors: Integer, String, and Enum.",[24,1309,1312],{"src":1310,"alt":1311},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvs-control-flow-4.jpg","Unity Visual Scripting – Select nodes","\nSelect nodes.\n",[16,1314,1316],{"id":1315},"select","Select",[12,1318,1319,1320,1322,1323,1325,1326,1328,1329,1331,1332,1334,1335,1338,1339,1341,1342,1344,1345,1347,1348,1350],{},"We saw how ",[42,1321,1278],{}," nodes translate a value into one of the multiple Flow branches.",[38,1324],{},"\nA ",[42,1327,1316],{}," node, in contrast, maps such values into other data values instead of Flows.",[38,1330],{},"\nLet’s say we have a boolean; we can map it to 5 when it’s true and 8 when it’s false. ",[38,1333],{},"\nA more advanced example will use ",[42,1336,1337],{},"Select On Integer",":",[38,1340],{},"\nin the Graph Inspector, we can add a few options, say -2, 4, and 12. In the graph, we can then connect a different Vector 3 to each option.",[38,1343],{},"\nSo now, when we pass one of the configured integer options, the node will provide us with the matching Vector 3.",[38,1346],{},"\nIt’s essential always to provide input to the Default port.",[38,1349],{},"\nIn addition to Boolean and Integer inputs, there are also  Select versions for Flow, String, and Enum.",[24,1352,1355],{"src":1353,"alt":1354},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvs-control-flow-5.jpg","Unity Visual Scripting – Toggle nodes","\nToggle nodes.\n",[16,1357,1359],{"id":1358},"toggle-flow","Toggle Flow",[12,1361,1362,1363,1365,1366,1368,1369,1371],{},"Like a light switch that can turn a light off and on, we can use the ",[42,1364,1359],{}," node to execute different branches depending on whether the Toggle is on or off.",[38,1367],{},"\nThe On and Off outputs flow will execute based on the current state.",[38,1370],{},"\nWe can connect Flows into the On\u002FOff inputs to change the state or into the Toggle input to flip it. Immediately after we switch a Toggle, it will perform the Turned On or Off Flows. And in any given point, we can determine the current state through the Is On output.",[260,1373],{},[12,1375,1376,1377,1380,1381,1383],{},"Another form is the ",[42,1378,1379],{},"Toggle Value"," node; it’s similar to the ",[42,1382,1359],{}," in a sense it has an On and Off switch. Yet, instead of executing different Flow branches, it will determine the output value based on the input On\u002FOff Values provided. When the Toggle is turned off, the output value will be whatever is connected to the Off input and vice-versa.",[24,1385,1388],{"src":1386,"alt":1387},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvs-control-flow-6.jpg","Unity Visual Scripting – Once node","\nOnce node.\n",[16,1390,1392],{"id":1391},"once","Once",[12,1394,1395,1396,1399,1400,1402,1403,1405,1406,1408],{},"When we use the ",[42,1397,1398],{},"On Update event"," node as our starting point, its Flow will execute each and every frame;  we can use the ",[42,1401,1392],{}," node to limit a portion of the Flow to run only one time, ignoring subsequent executions of the script.",[38,1404],{},"\nUsing the After output, we can differentiate between the first and subsequent executions.",[38,1407],{},"\nLast, we can use the Reset input Flow to rerun the Once Flow.",[24,1410,1413],{"src":1411,"alt":1412},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvs-control-flow-7.jpg","Unity Visual Scripting – Sequence node","\nSequence node.\n",[16,1415,1417],{"id":1416},"sequence","Sequence",[12,1419,1420,1421,1423,1424,1426],{},"The last node is ",[42,1422,1417],{},"; it will branch out the execution to multiple Flows and perform them in order.",[38,1425],{},"\nIt can be used for better organization and readability by splitting a long flow. For a more advanced example, our first branch in the Sequence can be interrupted and stop performing based on an If node. We can add another branch that will perform whether or not the first branch is executed entirely.",[272,1428],{},[12,1430,1431],{},"In the following article, we will dive into Variables...",{"title":282,"searchDepth":283,"depth":283,"links":1433},[1434,1435,1436,1437,1438,1439],{"id":1254,"depth":286,"text":1255},{"id":1277,"depth":286,"text":1278},{"id":1315,"depth":286,"text":1316},{"id":1358,"depth":286,"text":1359},{"id":1391,"depth":286,"text":1392},{"id":1416,"depth":286,"text":1417},{"480w":1441,"960w":1442},"\u002Fposts\u002F2021\u002F06-23_105\u002Fvisual-scripting-control-flow-480w.jpg","\u002Fposts\u002F2021\u002F06-23_105\u002Fvisual-scripting-control-flow-960w.jpg","2021-06-20","Using the Control flow nodes from the Unity Visual Scripting to make decisions and guid a Script Graph on dynamically executing gameplay based on the game’s current state.",{},"\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-105-control-flow",{"title":1204,"description":1444},"posts\u002F2021\u002F06\u002Fvisual-scripting-105-control-flow",[316,317],"91P7AQdrzW0wvSdHPCIzIQcC0LaYFTWJoQkst58G2wo","visual-scripting-105-control-flow",{"id":1453,"title":1454,"author":7,"body":1455,"category":302,"cover":1630,"date":1633,"description":1634,"extension":308,"meta":1635,"navigation":310,"path":1636,"seo":1637,"series":313,"stem":1638,"tags":1639,"youtube":318,"youtubeRange":319,"__hash__":1640,"slug":1641},"posts\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-106-variables.md","Variables",{"type":9,"value":1456,"toc":1619},[1457,1460,1481,1483,1487,1496,1501,1505,1508,1512,1518,1522,1528,1532,1535,1539,1542,1551,1553,1557,1560,1565,1574,1578,1597,1602,1611,1616],[12,1458,1459],{},"In this part, we’ll get to know Variables in Unity’s Visual Scripting. In short, variables are containers that store information and values.",[12,1461,1462,1463,1465,1466,1468,1469,1471,1472,1474,1475,1477,1478,1480],{},"A variable has a name, a type, and a value.",[38,1464],{},"\nThe value inside a variable can change throughout the game.",[38,1467],{},"\nImagine we have a cookie jar and an envelope. The cookie jar can contain different kinds of cookies, be it chocolate cookies or macaroons.",[38,1470],{},"\nAn envelope, on the other hand, may only contain letters or postcards.",[38,1473],{},"\nEvery container can contain any value as long as it shares the same data type.",[38,1476],{},"\nTherefore, we can’t put a cookie inside an envelope.",[38,1479],{},"\nAt any point, we can check which cookie is stored in the jar or replace it with another cookie.",[163,1482],{},[16,1484,1486],{"id":1485},"scopes","Scopes",[12,1488,1489,1490,1492,1493,1495],{},"Each variable belongs to a single Scope. We may want a variable to only be accessible to the current script graph, all scripts in the scene, or even remember its value after quitting the game.",[38,1491],{},"\nIn Unity’s Visual Scripting, there are five kinds of Scopes:",[38,1494],{},"\nGraph, Object, Scene, Application, and Saved.",[24,1497,1500],{"src":1498,"alt":1499},"\u002Fposts\u002F2021\u002F06-23_106\u002Fvs-variables-1.jpg","Unity Visual Scripting – Variables Scopes","\nVariables Scopes.\n",[30,1502,1504],{"id":1503},"graph-variables","Graph variables",[12,1506,1507],{},"Graph variables are local to the specific Script Graph. Therefore, they cannot be accessed or modified outside the script they are created in.",[30,1509,1511],{"id":1510},"object-variables","Object variables",[12,1513,1514,1515,1517],{},"Object variables are shared across all script graphs attached to a GameObject.",[38,1516],{},"\nNote that we can also edit Object variables in the GameObject Inspector.",[30,1519,1521],{"id":1520},"scene-variables","Scene variables",[12,1523,1524,1525,1527],{},"Scene variables are shared across all the script graphs in the current scene.",[38,1526],{},"\nWe can also edit these scope variables in the Inspector of the ‘Scene Variables’ GameObject placed in the scene. This GameObject will be created by Unity.",[30,1529,1531],{"id":1530},"application-variables","Application variables",[12,1533,1534],{},"Application variables are accessible from any script graph; their values remain even when the scene changes. However, they will reset once we quit the game.",[30,1536,1538],{"id":1537},"saved-variables","Saved variables",[12,1540,1541],{},"Saved variables will persist even after we quit and resume the game.",[12,1543,1544,1545,1547,1548,1550],{},"Why should we use a small scope when one could use a larger access scope, like the Application scope?",[38,1546],{},"\nThere may be times when different objects will have similar variables, for example, health points. All enemies will have health points, but we need to differentiate each enemy’s health separately, according to the damaged they have taken.",[38,1549],{},"\nIt can be confusing at first. But over time, it will become evident which scope to use.",[260,1552],{},[16,1554,1556],{"id":1555},"creating-a-variable","Creating a Variable",[12,1558,1559],{},"To add a variable, we choose the relevant scope tab, name the variable, and press enter. We can now select the data type the variable will remember, then we will fill in an initial value.",[24,1561,1564],{"src":1562,"alt":1563},"\u002Fposts\u002F2021\u002F06-23_106\u002Fvs-variables-2.jpg","Unity Visual Scripting – New Variable","\nNew Variable.\n",[12,1566,1567,1568,1570,1571,1573],{},"Under the Saved scope tab, we have Initial and Saved sub-tabs.",[38,1569],{},"\nIn the initial tab, we define the values that will automatically be created for new games.",[38,1572],{},"\nIn the saved tab, we can see the state of saved variables for our current computer.",[16,1575,1577],{"id":1576},"set-get","Set & Get",[12,1579,1580,1581,1584,1585,1587,1588,1590,1591,1593,1594,1596],{},"In the graph, we use the ",[42,1582,1583],{},"Get Variable"," node to get the information stored in it. This node gives us the current value stored in the variable. Searching it at the Fuzzy Finder will present us with different scopes to select from. We can also change the scope at the nodes themself.",[38,1586],{},"\nWe get our variable by either typing its name or selecting it from the list.",[38,1589],{},"\nIn this example, I have connected the ",[42,1592,1583],{}," node to a ",[42,1595,829],{}," node, which will print the variable’s value to the console.",[24,1598,1601],{"src":1599,"alt":1600},"\u002Fposts\u002F2021\u002F06-23_106\u002Fvs-variables-3.jpg","Unity Visual Scripting – Get Variable node","\nGet Variable node.\n",[12,1603,1604,1605,45,1608,1610],{},"We can also change a variable’s value at any time by using the ",[42,1606,1607],{},"Set Variable",[38,1609],{},"\nIn this example, I have created a Scene variable that remembers a boolean data type and set it to false.",[24,1612,1615],{"src":1613,"alt":1614},"\u002Fposts\u002F2021\u002F06-23_106\u002Fvs-variables-4.jpg","Unity Visual Scripting – Set variable node","\nSet Variable node.\n",[12,1617,1618],{},"Next up, we’ll discuss working with loops & collections.",{"title":282,"searchDepth":283,"depth":283,"links":1620},[1621,1628,1629],{"id":1485,"depth":286,"text":1486,"children":1622},[1623,1624,1625,1626,1627],{"id":1503,"depth":283,"text":1504},{"id":1510,"depth":283,"text":1511},{"id":1520,"depth":283,"text":1521},{"id":1530,"depth":283,"text":1531},{"id":1537,"depth":283,"text":1538},{"id":1555,"depth":286,"text":1556},{"id":1576,"depth":286,"text":1577},{"480w":1631,"960w":1632},"\u002Fposts\u002F2021\u002F06-23_106\u002Fvisual-scripting-variables-480w.jpg","\u002Fposts\u002F2021\u002F06-23_106\u002Fvisual-scripting-variables-960w.jpg","2021-06-21","Using Variables from the Unity Visual Scripting - containers that store information and values.",{},"\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-106-variables",{"title":1454,"description":1634},"posts\u002F2021\u002F06\u002Fvisual-scripting-106-variables",[316,317],"vWqyEFUrXuZhFybL8mN8jr4ZugF9rtibkmtLvwv3nc8","visual-scripting-106-variables",{"id":5,"title":6,"author":7,"body":1643,"category":302,"cover":1813,"date":306,"description":307,"extension":308,"meta":1814,"navigation":310,"path":311,"seo":1815,"series":313,"stem":314,"tags":1816,"youtube":318,"youtubeRange":319,"__hash__":320,"slug":321},{"type":9,"value":1644,"toc":1795},[1645,1647,1649,1651,1653,1655,1661,1663,1665,1679,1681,1683,1689,1691,1693,1703,1705,1707,1711,1713,1717,1719,1723,1725,1727,1733,1735,1737,1739,1741,1745,1747,1749,1757,1759,1761,1771,1773,1775,1781,1783,1785,1789,1791],[12,1646,14],{},[16,1648,19],{"id":18},[12,1650,22],{},[24,1652,28],{"src":26,"alt":27},[30,1654,33],{"id":32},[12,1656,36,1657,40,1659,45],{},[38,1658],{},[42,1660,44],{},[24,1662,50],{"src":48,"alt":49},[30,1664,54],{"id":53},[12,1666,57,1667,60,1669,64,1671,67,1673,71,1675,74,1677,45],{},[38,1668],{},[42,1670,63],{},[38,1672],{},[42,1674,70],{},[38,1676],{},[42,1678,77],{},[24,1680,82],{"src":80,"alt":81},[30,1682,86],{"id":85},[12,1684,89,1685,93,1687,97],{},[42,1686,92],{},[42,1688,96],{},[24,1690,102],{"src":100,"alt":101},[30,1692,106],{"id":105},[12,1694,109,1695,113,1697,116,1699,120,1701,124],{},[42,1696,112],{},[38,1698],{},[42,1700,119],{},[42,1702,123],{},[24,1704,129],{"src":127,"alt":128},[30,1706,133],{"id":132},[12,1708,136,1709,140],{},[42,1710,139],{},[30,1712,144],{"id":143},[12,1714,147,1715,45],{},[42,1716,150],{},[30,1718,154],{"id":153},[12,1720,157,1721,161],{},[42,1722,160],{},[163,1724],{},[16,1726,168],{"id":167},[12,1728,171,1729,174,1731,177],{},[38,1730],{},[38,1732],{},[24,1734,182],{"src":180,"alt":181},[12,1736,185],{},[12,1738,188],{},[16,1740,192],{"id":191},[12,1742,195,1743,198],{},[38,1744],{},[24,1746,203],{"src":201,"alt":202},[30,1748,207],{"id":206},[12,1750,109,1751,212,1753,215,1755,218],{},[42,1752,207],{},[38,1754],{},[42,1756,207],{},[24,1758,223],{"src":221,"alt":222},[30,1760,227],{"id":226},[12,1762,89,1763,232,1765,235,1767,238,1769,241],{},[42,1764,227],{},[38,1766],{},[38,1768],{},[42,1770,227],{},[24,1772,246],{"src":244,"alt":245},[30,1774,250],{"id":249},[12,1776,109,1777,255,1779,258],{},[42,1778,250],{},[38,1780],{},[260,1782],{},[30,1784,265],{"id":264},[12,1786,89,1787,270],{},[42,1788,265],{},[272,1790],{},[12,1792,276,1793,280],{},[42,1794,279],{},{"title":282,"searchDepth":283,"depth":283,"links":1796},[1797,1806,1807],{"id":18,"depth":286,"text":19,"children":1798},[1799,1800,1801,1802,1803,1804,1805],{"id":32,"depth":283,"text":33},{"id":53,"depth":283,"text":54},{"id":85,"depth":283,"text":86},{"id":105,"depth":283,"text":106},{"id":132,"depth":283,"text":133},{"id":143,"depth":283,"text":144},{"id":153,"depth":283,"text":154},{"id":167,"depth":286,"text":168},{"id":191,"depth":286,"text":192,"children":1808},[1809,1810,1811,1812],{"id":206,"depth":283,"text":207},{"id":226,"depth":283,"text":227},{"id":249,"depth":283,"text":250},{"id":264,"depth":283,"text":265},{"480w":304,"960w":305},{},{"title":6,"description":307},[316,317],{"id":1818,"title":1819,"author":7,"body":1820,"category":302,"cover":2036,"date":2039,"description":2040,"extension":308,"meta":2041,"navigation":310,"path":2042,"seo":2043,"series":313,"stem":2044,"tags":2045,"youtube":318,"youtubeRange":319,"__hash__":2046,"slug":2047},"posts\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-108-gameobjects.md","Game Objects",{"type":9,"value":1821,"toc":2026},[1822,1828,1833,1837,1848,1853,1857,1870,1872,1883,1888,1892,1895,1898,1907,1912,1916,1932,1937,1941,1950,1955,1959,1974,1976,1995,2000,2004,2011,2018,2020],[12,1823,1824,1825,1827],{},"A Game Object is any object that appears in our game’s scene – whether it’s a character, tree, camera, or light, if it’s in the scene, it’s represented by a Game Object.",[38,1826],{},"\nEvery Game Object contains Components that define its properties and behavior. Adding components and tweaking their configuration differentiates between a character, a light, or a camera object. Since every Game Object is in the game’s scene, it has at least a Transform component controlling its location in the world.",[24,1829,1832],{"src":1830,"alt":1831},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvs-gameobjects-1.jpg","Unity Visual Scripting – This and Game Object Literal nodes","\nThis and Game Object Literal nodes.\n",[16,1834,1836],{"id":1835},"referencing","Referencing",[12,1838,1839,1840,1843,1844,1847],{},"When we want to refer to a Game Object, we can use the ",[42,1841,1842],{},"This"," node, which will provide us the Game Object that the script is attached to. We can also use the ",[42,1845,1846],{},"Game Object Literal"," node to select a Game Object from the scene or a Prefab asset.",[24,1849,1852],{"src":1850,"alt":1851},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvs-gameobjects-2.jpg","Unity Visual Scripting – Set Active, Get Active Self and Get Active In Hierarchy nodes","\nSet Active, Get Active Self and Get Active In Hierarchy nodes.\n",[16,1854,1856],{"id":1855},"activation","Activation",[12,1858,1859,1860,1862,1863,1865,1866,1869],{},"An inactive Game Object exists in the scene but isn’t visible, nor does it or its components update.",[38,1861],{},"\nWe may want to prepare a few enemies at our level and activate them progressively.",[38,1864],{},"\nTo activate and deactivate a Game Object, we can use the ",[42,1867,1868],{},"Set Active"," node, passing it an activity boolean. This is like manually unchecking the check box in the Inspector.",[163,1871],{},[12,1873,1874,1875,1878,1879,1882],{},"We have two nodes to ask whether a Game Object is active or not; ",[42,1876,1877],{},"Get Active Self"," will tell us if the Game Object itself is marked as active, as in whether its Inspector’s checkbox is ticked on or off. The ",[42,1880,1881],{},"Get Active In Hierarchy"," node will check whether the Game Object is active and whether all of its parents are active. Usually, we use the Hierarchy version as it’s more practical.",[24,1884,1887],{"src":1885,"alt":1886},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvs-gameobjects-3.jpg","Unity Visual Scripting – Instantiate, Create Game Object and Add Component nodes","\nInstantiate, Create Game Object and Add Component nodes.\n",[16,1889,1891],{"id":1890},"creation","Creation",[12,1893,1894],{},"When making new Game Objects, we have two paths to choose from: duplicating an existing object or defining a new one.",[12,1896,1897],{},"To duplicate an existing Game Object, we can use the Instantiate node and pass it a scene Game Object or a Prefab asset. Perfect for creating enemies in real-time, shooting bullets, etc.",[12,1899,1900,1901,1904,1905,45],{},"We use the ",[42,1902,1903],{},"Create Game Object"," node to create an empty Game Object while we play. We can also use the node variant with a Name input to control the game object’s name.\nThe created Game Object is then available to us through the Result output; we can use it to set the position or add new components using the ",[42,1906,371],{},[24,1908,1911],{"src":1909,"alt":1910},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvs-gameobjects-4.jpg","Unity Visual Scripting – Get Component and Get Game Object nodes","\nGet Component and Get Game Object nodes.\n",[16,1913,1915],{"id":1914},"components","Components",[12,1917,1918,1919,1921,1922,1925,1926,1928,1929,45],{},"Speaking of components, we can access a Game Object’s Component with the Get Component passing the desired component type.",[38,1920],{},"\nWe can also go the other way around; if we have access to a component such as a Collider, we can use the ",[42,1923,1924],{},"Get Game Object"," node to retrieve the Game Object the Component is attached to.",[38,1927],{},"\nRemove a Component from a Game Object is achieves using the Component: ",[42,1930,1931],{},"Destroy",[24,1933,1936],{"src":1934,"alt":1935},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvs-gameobjects-5.jpg","Unity Visual Scripting – Destroy nodes","\nDestroy nodes.\n",[16,1938,1940],{"id":1939},"destroying","Destroying",[12,1942,1943,1944,1946,1947,1949],{},"We can use the ",[42,1945,1931],{}," node to remove a Game Object from the scene in real-time, along with all its components and scripts.\nIt’s helpful if we defeat an enemy and now want to remove it from the world.",[38,1948],{},"\nIn addition, we have a variant of Destroy with time which gives us the option to delay destroying the object.",[24,1951,1954],{"src":1952,"alt":1953},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvs-gameobjects-6.jpg","Unity Visual Scripting – Get Tag and Set Tag nodes","\nGet Tag and Set Tag nodes.\n",[16,1956,1958],{"id":1957},"tags","Tags",[12,1960,1961,1962,1964,1965,1967,1968,1970,1971,1973],{},"We can assign tags to Game Objects to categorize them.",[38,1963],{},"\nFor example, we may use a “Collectable” tag to define all items in the scene the player can collect.",[38,1966],{},"\nTags aid us in identifying Game Objects to treat them differently in our scripts.",[38,1969],{},"\nIn the Game Object’s Inspector, we assign a tag in the dropdown near the name.",[38,1972],{},"\nWe can either choose from Unity’s predefined tags or create a new one by choosing Add Tag.",[260,1975],{},[12,1977,1978,1979,1982,1983,1985,1986,45,1989,60,1991,1994],{},"Use the ",[42,1980,1981],{},"Get Tag"," node to retrieve the Game Object’s tag.",[38,1984],{},"\nWe can assign a different tag to a Game Object with the ",[42,1987,1988],{},"Set Tag",[38,1990],{},[42,1992,1993],{},"Compare Tag"," node, we can confirm if a Game Object’s tag matches another; we can use the resulting boolean to run a script only on specified objects.",[24,1996,1999],{"src":1997,"alt":1998},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvs-gameobjects-7.jpg","Unity Visual Scripting – Find Game Object With Tag and Find nodes","\nFind Game Object With Tag and Find nodes.\n",[30,2001,2003],{"id":2002},"finding","Finding",[12,2005,2006,2007,2010],{},"To look up Game Objects with a specified tag in the scene, we got the ",[42,2008,2009],{},"Find Game Object With Tag"," node. With this node, we can search for a Game Object at the scene by its tag; there are two variants for the node, one that returns the first matching object and another that returns all objects with the assigned tag.",[12,2012,2013,2014,2017],{},"We can also use the ",[42,2015,2016],{},"Find"," node to get a Game Object by its name.",[272,2019],{},[12,2021,2022,2023,2025],{},"Thank you for following along!",[38,2024],{},"\nUnity’s Visual Scripting provides us with tons of handy nodes to use, and while we did not cover all of them, you now got everything you need to know to start creating your games. We will explore more nodes in the following articles, interacting with Unity’s different systems, such as Physics, Input, and more...",{"title":282,"searchDepth":283,"depth":283,"links":2027},[2028,2029,2030,2031,2032,2033],{"id":1835,"depth":286,"text":1836},{"id":1855,"depth":286,"text":1856},{"id":1890,"depth":286,"text":1891},{"id":1914,"depth":286,"text":1915},{"id":1939,"depth":286,"text":1940},{"id":1957,"depth":286,"text":1958,"children":2034},[2035],{"id":2002,"depth":283,"text":2003},{"480w":2037,"960w":2038},"\u002Fposts\u002F2021\u002F06-23_108\u002Fvisual-scripting-gameobjects-480w.jpg","\u002Fposts\u002F2021\u002F06-23_108\u002Fvisual-scripting-gameobjects-960w.jpg","2021-06-23","Using Loops and Collections from the Unity Visual Scripting to repeat a section of our script multiple times.",{},"\u002Fposts\u002F2021\u002F06\u002Fvisual-scripting-108-gameobjects",{"title":1819,"description":2040},"posts\u002F2021\u002F06\u002Fvisual-scripting-108-gameobjects",[316,317],"8r7z9GqMD33m_J1_ZCK0lXkfA2nlPSalHqmYhn2nQ1w","visual-scripting-108-gameobjects",{"id":2049,"authorPage":310,"extension":326,"meta":2050,"name":2051,"social":2052,"stem":2057,"__hash__":2058},"team\u002Fteam\u002Fdanielle.yaml",{},"Danielle Elias",{"twitter":2053,"instagram":2054,"linkedin":2055,"website":2056},"ddanielleelias","https:\u002F\u002Fwww.instagram.com\u002Fdanielle_elias_","https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fdanielle-elias-847a1816a","https:\u002F\u002Fwww.danielleelias.com","team\u002Fdanielle","P4cpTrFv0g83_T48iFqh7voUrrlvEAlt5tc_ZtZvusk",1790297819922]