Instantiated Objects and Renderer.Bounds

Hello,

I have been successfully using the following snippet to figure out the bounds of an object in my scene on the x axis:

transform.renderer.bounds.max.x

However, when I use that snippet of code on an object I have instantiated from a prefab, that value is 0 (the size and extents are also 0). But, if I just drop that prefab into the scene prior to runtime and call the same code on it, I seem to get the proper values.

Is there something I may be doing incorrectly when it comes to instantiating objects and properly setting up their renderers?

Thanks,
Joe

The answer came to me last night; posting in case anyone has a similar problem.

After instantiating an object, I think it takes a frame for everything with the renderer to be fully running. Simply putting a yield after the instantiation of the prefab did the trick!

Indeed. Components don’t fully initialize straight away. New instances should be configured in the same call, but not queried.