The Duke of Cambridge has spoken of finding 'sanctuary in the service at Crathie Kirk' following the death of his mother in 1997.
He was speaking in his role as Lord High Commissioner to the General Assembly of the Church of Scotland as the assembly opened on Saturday.
William said he loved Scotland but remembered how he had been at Balmoral when he was told his mother had died in a car crash in Paris.
He said: "Scotland is incredibly important to me and will always have a special place in my heart. I've been coming to Scotland since I was a small boy.
"As I grew up I saw how my grandmother relishes every minute she spends here and my father is never happier than in walking among the hills.
"My childhood was full of holidays having fun in the fresh air, swimming in lochs, family barbecues with my grandfather in command, and yes the odd midge."
He added: "Scotland is a source of some of my happiest memories but also my saddest.
"I was in Balmoral when I was told my mother had died. Still in shock, I found sanctuary in the service at Crathie Kirk that very morning and in the dark days of grief that followed I found comfort and solace in the Scottish outdoors."
However, Scotland is also the place where he met his wife, the Duchess of Cambridge, 20 years ago this year, which he described as a memory of "great joy".
William was appointed by the Queen as Lord High Commissioner to the assembly, which is taking part in "blended" form due to the pandemic, with only a small number of people at the Assembly Hall in Edinburgh and others watching online.
The assembly began on Saturday with the installation of Lord Wallace of Tankerness QC as the next Moderator of the General Assembly, succeeding Rt Rev Dr Martin Fair.
Lord Wallace, a former deputy first minister of Scotland and Liberal Democrat MSP, is a member of St Magnus Cathedral in Orkney.
The assembly closes on Thursday afternoon and over the next few days will consider issues including proposals to reduce the number of presbyteries and the number of full-time ministry posts.
William began a week-long visit to Scotland on Friday and the Duchess of Cambridge will join him on Monday for the rest of the tour.