- Home /
Instantied GameObject Prefab doesn't have a height
I'm making a dynamic menu, and I use the instantiate method to load in the prefab, which is a parameter into the script from the Unity scene. I need the height of the instantiated pre-fab so I can use it to position the pre-fab correctly. The pre-fab is already showing up on the screen, so that's not an issue. However, the size of my instantiated prefab is always zero for some reason. Here is the code:
GameObject element = (GameObject)Instantiate(prefabSliderPanel); element.transform.SetParent(modifyTextureScrollPanel.transform,false);
Below is what I am printing to the console: element.GetComponent().rect.size: (508.0, 0.0) element.GetComponent().sizeDelta: (508.0, 0.0) bounds.size: (0.0, 0.0, 0.0) element.GetComponent().rect.height: 0
As you can see, there appears to be a width to the prefab, but not a height. I believe there should be a height since I can see the prefab on the screen, but its not at the right height (of course). I have also tried using a method I found on Stack Overflow which uses the MeshFilter of the object to calculate the bounds, but that also did not work. I was wondering if anyone knew why this may be occuring?