Unity restrict List to only choose its child gameObject

Hi,

I have a 3d model prefab which had several child objects. I want to show this child objects during the gameplay in a specific order so I made a script which has a List<GameObject> and is attached to the prefab itself. Is there any way to restrict what I am able to choose in the list? To make sure designers can only choose the child of the current object and nothing else.

You could use Unity’s OnValidate method, which will run every time values have changed in the inspector.

Simply check

foreach(GameObject go in myList) {
   if (go.transform.parent != this.transform) {
     Debug.LogWarning(go.name + " can't be added to this list, since it's not a direct child of " + this.name);
   go = null;

   }
}