(Quora.com)

(Image from pupa.ca)
Caterpillars do not have conscious awareness or foresight about becoming butterflies. Their transformation is driven by instinct and biological processes rather than conscious thought. When caterpillars reach a certain stage of development, they instinctively know to find a safe place to pupate and form a chrysalis or cocoon.
Inside the cocoon, a complex process called metamorphosis occurs, where the caterpillar’s body is broken down and restructured into that of a butterfly. While they are guided by genetic programming, they do not have the capacity to “know” what is happening in the way that we understand knowledge. Their behavior is purely instinctual, aimed at survival and reproduction.
They just feel the need to get some sleep, and build a bit of protection to keep themselves safe.
Do you speak from experience or …?