UnityException: Transform child out of bounds (253211)

Hi all! I am trying to create a 4-waypoints loop (Waypoint 0,1,2,3) on C#. While there is a Unity Exception: Transform child out of bounds. Does anyone know what is going on?

1 Answer

1

Hi,

I think it happens only when you add this script to an abject without children, oce you add at least one child it stops throwing errors. Its because on this line

Gizmos.DrawLine(transform.GetChild(transform.childCount - 1).position, transform.GetChild(0).position);

you get the position of first child and you do not check if it exist. If you add simple if(transform.childCount > 0) beofre this line it should solve it

that explains well! Thank you so much! @Immortus1