Using Lists with Bolt Visual Scripting

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so on the bold discord server there's a lot of questions flying around how do I create lists how do I add things to lists how do I use this is there a tutorial on list so I thought hey why not let's sit down and make a tutorial and show some the basics of how to use lists and so that's where I'll be going with the next two or three videos I'll build a very simple project we're gonna have a few simple objects in our scene that when we click on them they're gonna add themselves to a list they'll then turn themselves off we'll also add a UI element that will display all the names of the objects that are on that list and then lastly we'll create several buttons that will turn those objects back on whether they are the first object in the list the last object in the list maybe a random object in that list or we'll turn back on all the objects in that list so let's go ahead and get started the clickable objects so if we go over to our scene view you can see here that the scene is very simple I have a plane a cube a sphere a directional light in my camera that's it that's what we're gonna start with so first thing we're gonna do is create a macro so that when we click on the cube of the sphere some code will run so I'm gonna go to my macros folder right click create flow macro and I'm gonna call this clickable open up my flow graph now I'm gonna do things a little bit differently here and this is not the only way to do this but I like it because it's nice and simple and easy-to-implement I'm gonna add a unit and I'm gonna add the on pointer up event now usually this is used for you gooey or gooey events where we can click on a gooey object and this event will then get called we can use this with scene objects not just UI objects but we do have to add one more thing to our scene I'm gonna go up to my camera I'm gonna go to add component and I'm gonna add a physics ray caster this needs to be added to your camera in order for the on point up to get called when you click on scene objects now since I don't have any UI objects at the moment I also need to add in an event system so if I go up to create UI and add in event system now this will allow this event to get called when I click on those objects that have this flow macro so let's just test that real quick and see how it's working so what I'm gonna do is drag out the flow I'm gonna search for debug dot log add a unit string literal I'm just gonna simply add clicked and connect that up now I'm gonna go up to my cube and my sphere I'm gonna select both and I'm gonna add in a flow machine now I can add the flow machine onto multiple objects but I can't drag in drop my macro onto multiple objects so I'm gonna have to do that one at a time I'm gonna push play and then open up my console so I can see my debug message now if I click on my cube you can see that I get a clicked message in the console likewise if I click on the sphere I get a second clicked message you can see the number two there so we've got our code work and we now have clickable objects so if that's all you came for great I'll see you later we now have clickable objects you can interact with objects on your scene by just clicking on them we didn't need ray casting or anything particularly fancy we can use these on pointer up or you could also use the on pointer down events to click on your objects so we want to be able to add these objects to a list now just to keep things easy and simple I'm gonna make that list a scene variable so I'm gonna come over here to my variables window click on scene and I'm going to create a new variable clicked items hit the plus and then I need to choose the type and I'm gonna type list game object this is a little slow because there's a lot of different lists that bolt can pull up now this first option is the one I want list angle brackets game object now you'll see a bunch of different things here you may see an eye list option in the fuzzy finder or in various types and those will work the difference is that I list not to get too technical here I list is an interface that the list class implements you will also see in bolt you'll see the äôt list which I'm gonna skip for this tutorial a ot lists are types that you need to use if you are building for iOS or WebGL so I'm gonna add that in add my type and you can see here I can add various values to my list if I wanted to add objects before runtime but I don't want to do that I'm gonna leave that as is I'm gonna go back to my flow macro I'm gonna delete these debug messages I'm gonna drag this clicked items list into my flow macro and so what we're trying to do here is add this game object to a list so if I right click add unit come down here to collections lists and add list item and so what we want to add to this list is the object that this flow macro is on so I'm gonna right click Add unit and I'm a search for self and I'm gonna connect that up so let's connect everything up and see how it works I'm gonna connect up my list and my flow and let's press play and see what happens in my variables window if I click on scene I can see my clicked items list and now when I click on a cube you can see that the cube was added as a value I can click on the sphere and the sphere was also added I've noticed here that the UI here is a little buggy for Liss I'm not gonna worry about that too much the functionality is all good if I continue to click on these objects I'm going to continue to add them to the list I'm gonna make the list bigger and bigger and so I don't want to continuously add the same cube or the same sphere to the object so what I want to do is check if the list contains that object already and if it does I don't want to add it to the list if it doesn't contain that object I do want to add it to that list so let's go back out of play mode and go back to our macro so I'm gonna get disconnect my flow and I'm gonna add a couple more units I'm gonna right-click and I go to collections lists we're gonna use this unit right here list contains item so what this is gonna do is check and see does this list have this item and it's gonna return a boolean out the right hand side I'm gonna drag out my list and I'm gonna move myself node over because what we want to check is does this list have the game object that this fluo macro is on we're gonna take that boolean up into a branch and if that's false we're gonna go over here and add ourselves to that list I'm gonna connect up my flow to the branch and there you go that's all there is to it we're now checking to see whether this object is in the list or not let's push play and see what happens again in my variables window I'm gonna click on scene so I can see my scene variables now if I click on my cube you can see that it gets added but if I click again you can see that it's not adding it to the list whereas if I click on the sphere the sphere does get added and again if I click again it doesn't get added because it's already in the list so there you go we've got clickable objects functioning in our scene we're also clicking on those objects and adding them to our list so our next view we're gonna create a UI text element that's going to display all of the names of the objects that are in the list that's gonna use a for each loop to iterate through the list get the name of each of the game objects and display it in a text box so I hope that was helpful and I hope you'll join me for my next video with lists in both you
Info
Channel: One Wheel Studio
Views: 13,134
Rating: undefined out of 5
Keywords: Bolt, Visual Scripting, List, Unity Tutorial, Tutorial, Click on Object, On Pointer, Bolt Tutorial, Unity3D, game
Id: iy6K2uOGykI
Channel Id: undefined
Length: 6min 33sec (393 seconds)
Published: Tue Dec 18 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.