Hello.
So I don’t understand how this works and how to avoid this. I wanted to make inventory where I delete old item slots and add new ones and fill 'em up with items. The problem is that when I remove old slots they are still found when I try something like GetChild(). How do I ignore destroyed objects?
Here is a simple example of my problem. Even after I destroy 1st object and add “item 2”, GetChild() still prints that “item 1” is the 1st child.
private void Start()
{
GameObject go1 = Instantiate(new GameObject(), transform);
go1.name = "item 1";
Debug.Log(transform.GetChild(0).name);
Destroy(transform.GetChild(0).gameObject);
GameObject go2 = Instantiate(new GameObject(), transform);
go2.name = "item 2";
Debug.Log(transform.GetChild(0).name);
}
Also, I don’t understan why 2 it created another 2 objects at the bottom (they are called “New Game Object”)?!