I am getting MissingReferenceException but it doesnt make sense, since I am destroying a GameObject, but I never mention it in the code again.
The whole error in console:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Transform[] currentShips = shipParent.GetComponentsInChildren<Transform>();
if (currentShips.Length > 0)
{
foreach (Transform obj in currentShips)
{
Destroy(obj.gameObject);
}
}
It doesn't make sense to me since there is no other references to currentShips (and also of course not to obj, since its local). I also tried checking if currentShips != null in the if statement, but no change. I am guessing its just a little simple thing I am overlooking, but thats what this site is made for, right?
shipParentitself is destroyed with all its children and afterwards the next child in loop crashes. Try usingforeach (Transform child in transform)instead to get the child objects without the parent