The father of murdered six-year-old Alesha MacPhail sold cannabis to the teenager accused of killing her, a court has heard.
Robert MacPhail, 26, told the High Court in Glasgow he had done deals with the 16-year-old.
The schoolgirl was found dead in woodland in July last year on the Isle of Bute.
She had been spending a summer break with her father and grandparents in the house they shared.
The accused, who cannot be named because of his age, denies taking her from her bed before raping and murdering her on July 2 last year.
Alesha’s father identified him in the courtroom and told the jury: “I used to sell him cannabis.”
Mr MacPhail, who is unemployed, said he had last sold him the drug a few months before Alesha’s murder.
He said he stopped after the teenager’s mother told his partner, Toni McLachlan, to stop.
The court heard the deals usually took place at a bus shelter across from his own mother’s house in Ardbeg Road, where he then lived along with Ms McLachlan, 18.
The pair were in bed on the morning of July 2 when Alesha’s grandparents came in to say she was missing, and all four began hunting around the house and outside for the schoolgirl.
Mr MacPhail said he had put his daughter to bed the night before with a Peppa Pig DVD.
“I told her I would see her in the morning and that was the last time I saw her,” he said.
Mr MacPhail said his relationship with Alesha’s mother Georgina Lochrane in Coatbridge, North Lanarkshire, had broken down months after she was born.
He said he saw his daughter every second weekend and during the holidays.
Mr MacPhail said his daughter “loved” spending time on his home island, going to the beach and playing at the park.
Asked about Alesha’s relationship with Ms McLachlan, he said it was “great”.
“They both loved each other to bits,” he said.
The 16-year-old accused of Alesha’s murder has lodged a special defence blaming Ms McLachlan for her death.
He also denies attempting to defeat the ends of justice by disposing of clothing and a knife.
Alesha’s grandfather Calum MacPhail, 49, described the desperate search after they realised she was not in her bed.
He said: “We searched under all the beds, in all the wardrobes to see if she had crawled away somewhere.
“There was no sign of her anywhere. I threw some clothes on and went outside.”
After driving around, looking for Alesha at the park and the putting green, he later saw police had cordoned off an area and was told to go to Rothesay police station with the rest of the family.
Visibly distressed, he said: “We were all put into a room and about five minutes later a police officer came in and said ‘we found her but she’s passed’”.
Alesha’s grandmother Angela King, 47, had made a call to the police at 6.23am, around 10 minutes after realising she was not in her bed.
In the call played to the jury, she continued to check cupboards as she told the handler: “We’ve looked all through the house and she’s nowhere to be seen.”
Her partner had earlier told the court that the key to the lock on the front door of the top-floor flat was often left in the door during the day to allow family members to come and go.
He said: “In Rothesay a lot of people leave their door unlocked.”
Ms King said the key was still in the door when she went to bed in the early hours of July 2.
She said: “The key was in the lock and I’d forgotten to take the key back out of the door.”
The trial continues on Wednesday.