You could use Unity's OnValidate method, which will run every time values have changed in the inspector.
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnValidate.html
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;
}
}
↧