Jurors in the Alesha MacPhail murder trial have heard that her father sold cannabis to the teenager accused of killing her.
Robert MacPhail, 26, admitted doing deals with the 16-year-old boy who lived on the Isle of Bute.
The teenager - who cannot be named because of his age - denies abducting, raping and murdering Alesha last July.
He has lodged a special defence claiming the crime was committed by a woman called Toni Louise McLachlan.
Alesha's body was found in the grounds of a former hotel on 2 July last year.
Giving evidence at the High Court in Glasgow, Mr MacPhail said he last sold the drug to the 16-year-old accused a few months before Alesha was killed.
The court heard he stopped supplying cannabis to the accused after the teenager's mother made a request via her friend.
The jury was told the friend was an aunt of Mr MacPhail's partner, Toni McLachlan.
Mr MacPhail, who is unemployed, said he sold cannabis to fund his own use of the drug and used to arrange transactions via Facebook Messenger and other means.
The jury were later shown Facebook messages between Mr MacPhail and the accused which indicated the pair had fallen out in February last year over a £10 drug debt.
The messages indicated the source of the dispute was the quality of cannabis the accused had been sold.
Brian McConnachie QC, for the accused, later asked Mr MacPhail: "Did it ever cross your mind that your drug dealing might have some relevance to Alesha being taken?"
The witness replied: "It did not".
Mr MacPhail told the court that the night before she died, Alesha came into the room he shared with Ms McLachlan and had some of his dinner.
She then went to her room to watch a Peppa Pig DVD.
Mr MacPhail last saw his daughter when she got up between 22:30 and 23:00 on 1 July.
He said he went to bed with Ms McLachlan around 23:30 and only became aware Alesha was missing when his parents woke him up around 06:30 the following day.
A frantic search followed and locals joined in when Mr MacPhail's mother posted an appeal on Facebook.
He was later taken to the police station to be informed his missing daughter's body had been found.
The jury heard Alesha was only a few days into a three-and-a-half week summer break on the Isle of Bute when she was murdered.
'Loved each other'
She had been staying with Mr MacPhail, his parents and Ms McLachlan in a three-bedroom converted attic flat on Ardbeg Road.
Mr MacPhail, 26, told the court he split up with Alesha's mother around three months after his daughter was born.
He later started dating Ms McLachlan, 18, and they had been together for two years.
He also told the jury his girlfriend was involved in his drug dealing and both handed over cannabis and collected money from his customers.
Asked by Mr McSporran how Ms McLachlan got on with his daughter, the witness replied: "Great. They both loved each other to bits. Ever since Toni met her, from day one."
Jurors were earlier shown pictures of the crime scene.
Prosecutor Iain McSporran QC issued a warning to the jury before the images of the six-year-old with a pile of clothing next to her were shown on public screens in the court.
The images also showed the wooded area and the disused hotel on the Isle of Bute where she was found.
A number of people, including relatives of Alesha, left the court before the pictures were shown.
Jurors were previously told Alesha's naked body was found by a man at 08:54 on 2 July in the grounds of the former Kyles Hydropathic Hotel.
Alesha's grandfather Calum MacPhail, 49, last saw Alesha when she came in and jumped on his bed the night before she was discovered.
The girl said to him: "Goodnight, grandpa."
The next morning Mr MacPhail got up for work around 06:00 - but could not find Alesha in bed.
He alerted his family adding: "We searched under beds, in wardrobes, but there was no sign of her anywhere."
Mr MacPhail drove around Bute to look for Alesha.
He eventually spotted police tape at an area cordoned off and begged for information before being told to go the local police station.
Fighting back tears, the creamery worker recalled: "We were put into a room. Five minutes later, a police officer said: 'We have found her but she has passed.'"
'Beautiful, happy girl'
Earlier, Mr MacPhail said his partner, Angela King, often left the key in their front door.
He added: "It was one of the things about Rothesay that a lot of people leave their door unlocked."
Ms King, 47, later described her granddaughter as a "beautiful, beautiful, happy girl".
A recording of the 999 call she made at 06:23 on 2 July was also played to the court.
Ms King was later asked by the boy's QC Mr McConnachie of being aware of her son Robert's drug dealing.
Angela replied: "He never admitted it, but I had my suspicions."
Prosecutors allege the accused boy was armed with a knife when he took Alesha from her bed at a house in Ardbeg Road.
It is claimed he carried the schoolgirl to the site of the former hotel, removed her clothes and suffocated her before raping and murdering her.
The teenager faces a separate charge of attempting to defeat the ends of justice by disposing of clothes he had been wearing.
The trial continues.
Why is the BBC not naming the accused?
It is illegal in Scotland to publish the name, address, school or any other information which could identify anyone under the age of 18 who is the accused, victim or witness in a criminal case
This law applies to social media as well as to websites, newspapers and TV and radio programmes.
However, the name of victims who have died can be published - so the BBC and other outlets are able to identify Alesha MacPhail.
What is a special defence of incrimination?
Ahead of their trial, the accused can lodge a special defence which will result in them being acquitted if it is accepted by the court.
These defences include self-defence (they were defending themselves from attack), alibi (they were somewhere else when the crime was committed) and mental disorder (the accused is not responsible for their actions because they were suffering from a psychiatric condition).
In this case, the accused has lodged a special defence of incrimination - meaning he has claimed that someone else (a woman called Toni McLachlan) was responsible for Alesha's death.
It will be for the jury to decide whether or not they accept this special defence after hearing the evidence in the case.