Trying to create an endless path with prefabs that have different z values, not able to reference z size of prefabs.

I’m creating an endless flyer in which prefabs are loaded and placed as the player flys further into the path.

Right now the prefabs all take up exactly 500 units of space and their spawn points are hard coded so that they simply spawn 500 points further along the z axis then the path prefab before them.

I’m attempting to make this system more flexible, allowing for different sized prefabs.

I have tried

GetComponent().bounds.size.z

GetComponent().bounds.size.z

GetComponant().(just about everything)

and all kinds of other options none of these return the real value of the prefab, and thus my paths build on top of one another.

The prefabs are empty game objects with no renderers as of now, I did add mesh renderers to them to try out the ().bounds… option but this returns with a value of 0.

Maybe it’s an idea to encapsulate your prefabs with a collider. This collider will have the same dimensions as your prefab, and the size can be retrieved using the GetComponent().bounds; You need to set it to a trigger, or maybe inactive (don’t know if inactive Colliders can be reached), so you don’t fly into a collider. Haven’t tried this method, but I don’t know why it wouldn’t work. As this also requires some work, and isn’t at all automatic, you might as well just write a script to keep some information. Drag the extra script on the prefab and just enter the size in the inspector.