People are more likely to help when you put a little more effort in creating a good post.
Use âcodeâ-tags, so your code shows up code-formatted instead of regular text.
Share the complete error message, it has valuable information.
Your âItemâ class should already have a gameObject associated with it, as well as any text or images. Which should be cached into that class. So any call to a particular âItemâ just needs to reference that variable within that class. So technically that function should look like this:
public void ListItems()
{
foreach (var item in Items)
{
itemName.text = item.myText;
itemIcon.sprite = item.myIcon;
}
}
I removed the gameObject.Instantiate() because Iâm not sure exactly how that works within correlation, of what exactly it is you need to do. But once you have a class reference, you should be easily able to get anything in said class, whether it be the gameObject, Renderer, Collider, Rigidbody, or any declared variables like myIcon, myText, etcâŚ
Always cache important, or needed, variables and have them as âpublicâ. So all you need to do is this.variable = className.variable.
The error message will have two numbers in parentheses at the end. The first number is the line number where the error occurred, the second number is the column where the error occurred. Once you know that, then itâs pretty easy to identify which object is null.