Oh wow, yeah, you're right. That's a pretty big mistake on my part there, I think I intended to, I must have just forgotten when writing the script. If that caused anyone any grief, real sorry. I'll pin this, in the hope others might see it. I'll update the script, post the correction on GitHub and update the video description. Sounds like you know how to fix it, Thomas, do you need a hand or is it ok?
Wellllll I came up with my own fix because I only watched half the video at first >.> Mine takes more processing power to handle I think? if (GetComponentInChildren() != null) { ButtonListButton[] BLB = GetComponentsInChildren(); foreach (ButtonListButton i in BLB) { Destroy(i.gameObject); } } When I tried to use your fix I went with buttons.Add(button) at the end of the second foreach loop and that didn't fix it.
Hmmm, yeah, that should add the button to the list correctly. You did that not after, but within the foreach loop, yeah? That should add the button to the list, then when next generated and the list is cleared (so, you'd do the first foreach loop again in a new function), they should be destroyed automatically. Your method would be a bit heavier, just cause of the GetComponent functions and the temporary array. It's not likely a huge issue but yeah, weird the original method doesn't work for you. Happy to have a look over the script for you, if you like. Sorry again for causing any frustration. =\
No worries! I got what I came here for regardless (and at least I know my fix is process heavy if I run into problems down the road)! Bookmarked your page for further watching later. Keep cranking out awesome tutorials!
'buttons.Add(button.gameObject);' at the end of the 2nd loop. Not sure if this was necessary, but I also moved 'buttons = new List();' to the Start function.
For anyone watching this tutorial more recently, if you create the default UI Button of "Button - TextMeshPro" You will need to make these mods on the ButtonListButton Script: Import: 'using TMPro;' and update the var 'private Text myText;' to the type 'private TextMeshProUGUI myText;'.
Thank you SO MUCH. I searched Google and TH-cam for days looking at how to do this; all other tutorials were severely difficult to follow. You just saved me copious amounts of time. Cheers
Very, very, very helpful series. This covers one of my most critical areas in my game and I wouldn't have had a clue how to do it. You've probably saved me weeks of time. THANK YOU VERY MUCH. I now have it working, at least first pass -- I haven't proven yet that it works second time around. I did have to make adjustments for the list issue commented on by others. Your explanation and illustration was very good, despite being somewhat unplanned/unscripted. I only had troubles sometimes, following your rapid mouse movements -- slow that down or switch to a larger mouse pointer icon.
Awesome vids. Thanks for the great work. Just a tip -- remember to add an OnClick event to the button, and to add the button as the reference for the event, and to select the ButtonListButton.OnClick() method as the event. And you should be all set.
Hi. I'm confused and need more info. "add an OnClick event to the button..." -- that's what he showed in the video, right? But I don't follow the other two suggestions. Could you flesh that out a bit more?
@@RayJ1216 Not sure if you still need this, but for anyone coming across this like I did, this video shows what Chewy is talking about th-cam.com/video/kdkrjCF0KCo/w-d-xo.html
Okay yeah Im going to leave this tutorial since I dont understand what is going on. Altho did enjoy the last part of the series. Learned a few things. Dont understand coding in that length where I can follow this tutorial.
Bro... I must say firstly, that I very much appreciate your very detailed and specific tutorials on this. It definitely helped me understand and integrate this into my inventory system where I was lost for days... However... Nearing the end of this, when needing to delete all the game objects... I legit was fried and got stuck on this for quite some time... And for some reason I stupidly assumed it was myself doing a typo, since I followed your tutorial to a T. HOWEVER.. You left out a HUGE puzzle piece, which usually I think i'd of realized, but due to some one who is learning (as IM sure most here are) this was very confusing and set me back by hours... Anyways... You forgot to add somewhere in the code, when doing button = Instantiate(template) as GameObject, ETC,ETC, You need to add the actually object into your newly created Array Of GameObjects.. I dont think you realized, that your edge case for deleting the duplicates, was never hitting, because you never added anything into your list.. Thus, it was always hitting 0... So ya, somewhere under where your instantiating the initial template add: "buttons.Add(button);". Anyways aside from that, thanks very much for this bro! This Got me much further in my desired direction than anything ive come across or been able to figure out the past month..
I've copied this pretty exactly. Now, I wonder if you can outline how to have the scrollbar positioned at an intended location [0-1] via code? I've tried setting the 'value', but get random results. I've read that it's because of being a dynamic structure. I can read out the value just fine; I can set it to itself fine. But when set to a different value, I get garbage results.
I do Have a much needed question though, Would you by chance happen to know, how to make it clickable, WITHOUT using a button? As my particular setup, I dont have buttons, I have a list of A template I created myself showing the sprite, item name, etc. Was curious how to make this particular template slot within the list, clickable? Or would I somehow have to wrap the image around the button? Thanks.
i'm sure i've set the button object up correctly. but now it's working after i adding this this.gameObject.GetComponent ().onClick.AddListener (OnClick); on SetText method :D
I had the same issue. I am not sure if Unity knows to automatically run an 'OnClick' function in a script attached to a button. I resolved this in the inspector. In the editor select the Button (template), then in the inspector, under 'On Click()', add an event, next reference the button and then the OnClick function from the 'ButtonListButton' script. This worked perfectly for me, no modification to any code.
I get a NullReferenceException: Object reference not set to an instance of an object on line 13 of ButtonListButton where the name is being set on the button basically. I cant figure out why this is happening. Please help..
Heya Pankaj, that error means it's not finding the text object or component, make sure you've drag and dropped the text object into that field in the inspector.
Hey. I am sorry I know this is not a part of this video but I am stuck and I thought maybe you could help me here. I got the list working and have implemented a way to delete a button once its clicked. However, I am unable to make the remaining list scroll up automatically once a button on top is deleted. Do you think you will be able to help me with this? I would be really helpful if you could assist me here. Thanks.
Hi Pankaj. Were you using a layout group? That should automatically re position any objects if one gets deleted. If you look at the objects in the scene after you delete a button, is there anything still there? You might need to make sure you're deleting the button's game object and not the button component itself (make sure you use .gameObject when you destroy the button)).
Man, having spent the day watching videos on how do do stuff in unity this is the very worst. Some have just made their explanations too complex, involving too many other factors than the one in question. Once in a while you find someone who has kept it very simple so the only new thing they show is the subject in question, they are the stars. At the very least pretty much everyone knows what they are going to do before they start recording, except for you... Any by the way I am not a beginner, I've been programming games for 40 years.
Your solution in the second half doesn't work. You never add anything to the buttons List so it never equals more than 0.
Oh wow, yeah, you're right. That's a pretty big mistake on my part there, I think I intended to, I must have just forgotten when writing the script.
If that caused anyone any grief, real sorry.
I'll pin this, in the hope others might see it. I'll update the script, post the correction on GitHub and update the video description.
Sounds like you know how to fix it, Thomas, do you need a hand or is it ok?
Wellllll I came up with my own fix because I only watched half the video at first >.>
Mine takes more processing power to handle I think?
if (GetComponentInChildren() != null)
{
ButtonListButton[] BLB = GetComponentsInChildren();
foreach (ButtonListButton i in BLB)
{
Destroy(i.gameObject);
}
}
When I tried to use your fix I went with buttons.Add(button) at the end of the second foreach loop and that didn't fix it.
Hmmm, yeah, that should add the button to the list correctly. You did that not after, but within the foreach loop, yeah?
That should add the button to the list, then when next generated and the list is cleared (so, you'd do the first foreach loop again in a new function), they should be destroyed automatically.
Your method would be a bit heavier, just cause of the GetComponent functions and the temporary array. It's not likely a huge issue but yeah, weird the original method doesn't work for you. Happy to have a look over the script for you, if you like.
Sorry again for causing any frustration. =\
No worries! I got what I came here for regardless (and at least I know my fix is process heavy if I run into problems down the road)!
Bookmarked your page for further watching later. Keep cranking out awesome tutorials!
'buttons.Add(button.gameObject);' at the end of the 2nd loop. Not sure if this was necessary, but I also moved 'buttons = new List();' to the Start function.
For anyone watching this tutorial more recently, if you create the default UI Button of "Button - TextMeshPro"
You will need to make these mods on the ButtonListButton Script:
Import: 'using TMPro;'
and update the var 'private Text myText;' to the type 'private TextMeshProUGUI myText;'.
Thank you SO MUCH. I searched Google and TH-cam for days looking at how to do this; all other tutorials were severely difficult to follow. You just saved me copious amounts of time. Cheers
Very, very, very helpful series. This covers one of my most critical areas in my game and I wouldn't have had a clue how to do it. You've probably saved me weeks of time. THANK YOU VERY MUCH. I now have it working, at least first pass -- I haven't proven yet that it works second time around. I did have to make adjustments for the list issue commented on by others. Your explanation and illustration was very good, despite being somewhat unplanned/unscripted. I only had troubles sometimes, following your rapid mouse movements -- slow that down or switch to a larger mouse pointer icon.
Thank you so much! This Pt 3 and also the Pt 2 helped me create my own scrollable list of buttons I needed. You are awesome!
This was super useful. Thank you very much indeed! Encouraged me to check out your other offerings!
Awesome vids. Thanks for the great work. Just a tip -- remember to add an OnClick event to the button, and to add the button as the reference for the event, and to select the ButtonListButton.OnClick() method as the event. And you should be all set.
Thank you very much for this comment! Made my day!
Hi. I'm confused and need more info. "add an OnClick event to the button..." -- that's what he showed in the video, right? But I don't follow the other two suggestions. Could you flesh that out a bit more?
@@RayJ1216 Not sure if you still need this, but for anyone coming across this like I did, this video shows what Chewy is talking about th-cam.com/video/kdkrjCF0KCo/w-d-xo.html
This is a GREAT UI tutorail! Well done! 👍🤓
Okay yeah Im going to leave this tutorial since I dont understand what is going on. Altho did enjoy the last part of the series. Learned a few things. Dont understand coding in that length where I can follow this tutorial.
Super helpful tutorial! Your videos are well-made and easy to follow. Thanks so much and keep up the good work!
Cheers, Saki. Appreciate the kind words. =)
Bro... I must say firstly, that I very much appreciate your very detailed and specific tutorials on this. It definitely helped me understand and integrate this into my inventory system where I was lost for days... However... Nearing the end of this, when needing to delete all the game objects... I legit was fried and got stuck on this for quite some time... And for some reason I stupidly assumed it was myself doing a typo, since I followed your tutorial to a T. HOWEVER.. You left out a HUGE puzzle piece, which usually I think i'd of realized, but due to some one who is learning (as IM sure most here are) this was very confusing and set me back by hours... Anyways... You forgot to add somewhere in the code, when doing button = Instantiate(template) as GameObject, ETC,ETC, You need to add the actually object into your newly created Array Of GameObjects.. I dont think you realized, that your edge case for deleting the duplicates, was never hitting, because you never added anything into your list.. Thus, it was always hitting 0... So ya, somewhere under where your instantiating the initial template add: "buttons.Add(button);". Anyways aside from that, thanks very much for this bro! This Got me much further in my desired direction than anything ive come across or been able to figure out the past month..
Hey, thanks for this tutorial. Exactly what I needed :)
Nice strat man. Saved my day, ty!
Thanks for this!
thanks
I've copied this pretty exactly. Now, I wonder if you can outline how to have the scrollbar positioned at an intended location [0-1] via code? I've tried setting the 'value', but get random results. I've read that it's because of being a dynamic structure. I can read out the value just fine; I can set it to itself fine. But when set to a different value, I get garbage results.
I do Have a much needed question though, Would you by chance happen to know, how to make it clickable, WITHOUT using a button? As my particular setup, I dont have buttons, I have a list of A template I created myself showing the sprite, item name, etc. Was curious how to make this particular template slot within the list, clickable? Or would I somehow have to wrap the image around the button? Thanks.
Thanks from Ukraine!!!
thanks man
i following this tutorial but when i click the button it doesn't show any debug log text :(
Hi mate, best guess, make sure you've set the button object up correctly and it's running the right function when clicked.
i'm sure i've set the button object up correctly. but now it's working after i adding this
this.gameObject.GetComponent ().onClick.AddListener (OnClick);
on SetText method :D
Interesting, yeah, seems like it wasn't sure what to do when clicked.
Hey, if it's all fixed, awesome. Good work. =)
I had the same issue. I am not sure if Unity knows to automatically run an 'OnClick' function in a script attached to a button. I resolved this in the inspector. In the editor select the Button (template), then in the inspector, under 'On Click()', add an event, next reference the button and then the OnClick function from the 'ButtonListButton' script. This worked perfectly for me, no modification to any code.
@@RickyVaughn2 Big brain, thanks man!
I get a NullReferenceException: Object reference not set to an instance of an object on line 13 of ButtonListButton where the name is being set on the button basically. I cant figure out why this is happening. Please help..
Heya Pankaj, that error means it's not finding the text object or component, make sure you've drag and dropped the text object into that field in the inspector.
Thank youuu.. That was indeed the error. Thanks a lot :)
No problems, happy it works for you. =)
Hey. I am sorry I know this is not a part of this video but I am stuck and I thought maybe you could help me here. I got the list working and have implemented a way to delete a button once its clicked. However, I am unable to make the remaining list scroll up automatically once a button on top is deleted. Do you think you will be able to help me with this? I would be really helpful if you could assist me here. Thanks.
Hi Pankaj. Were you using a layout group? That should automatically re position any objects if one gets deleted.
If you look at the objects in the scene after you delete a button, is there anything still there? You might need to make sure you're deleting the button's game object and not the button component itself (make sure you use .gameObject when you destroy the button)).
very helpful thanks !
at 2:55 hahaha...
Man, having spent the day watching videos on how do do stuff in unity this is the very worst. Some have just made their explanations too complex, involving too many other factors than the one in question. Once in a while you find someone who has kept it very simple so the only new thing they show is the subject in question, they are the stars. At the very least pretty much everyone knows what they are going to do before they start recording, except for you... Any by the way I am not a beginner, I've been programming games for 40 years.