The bug occurs in two cases. 1) When I restart the scene. 2) When I go to another scene and then come back. The game works correctly only after the first start of the scene.
The essence of the bug is that there is an error:
MissingReferenceException: The object of type ‘Transform’ has been destroyed but you are still trying to access it.
Although looking at the instpector, you can see that there is a link to the object and clicking on it in the hierarchy opens this object. To get around this problem I used GameObject.Find and it worked, but there are a lot of such links and I need to fix it another way.
The code where the error concerns the ropeParent object:
if (ropeParent.childCount > 0)
{
Destroy(ropeParent.GetChild(0).gameObject);
}
ropeParent field:
[SerializeField] private Transform ropeParent;
Inspector screenshots: