SortingGroup[] sortingGroups;
SortingGroup[] SortingGroups => sortingGroups ?? (sortingGroups = GetComponentsInChildren<SortingGroup>());
void OnEnable()
{
foreach (SortingGroup sortingGroup in SortingGroups)
sortingGroup.enabled = true;
}
void OnDisable()
{
foreach (SortingGroup sortingGroup in SortingGroups)
sortingGroup.enabled = false;
}
https://forum.unity.com/threads/invalid-sortinggroup-index-set-in-renderer.586450/#post-6462529
The script with the similar code should be attached to the root of pooled object.
Hope, it will help you.