But the impact of these changes aren't yet clear, the researchers added.
Special type of ultrasound
The study included 82 pregnant women with diabetes, 26 obese pregnant women and 70 healthy pregnant women.
The heart muscle of the foetuses in obese women and those with diabetes showed changes that weren't seen in the foetuses of healthy women.
The changes were only visible with a special type of ultrasound of the heart called echocardiography. The changes weren't seen using standard echocardiography, the study found.
The findings were to be presented at a European Society of Cardiology (ESC) meeting in Spain.
Findings from meetings are typically seen as preliminary until they're published in a peer-reviewed journal.
"Diabetes and obesity are major epidemics of the present century.
"I see a lot of mothers with one or both conditions in my clinical practice and wanted to investigate if these maternal conditions had any effect on the foetal hearts," study author Dr Aparna Kulkarni, a New York City paediatric cardiologist from Montefiore Medical Centre, said in an ESC news release.
But, while these findings are important, "I don't want pregnant women with diabetes or obesity to think that something will definitely go wrong with their pregnancy.
"We need more answers about what impact diabetes and obesity in the mother may have on the child after birth, before coming to firm conclusions about implications for the health of the baby," Kulkarni noted.
Further research is needed to determine when these foetal heart muscle changes occur during pregnancy, if anything can be done to prevent them, and whether they affect heart health later in life, Kulkarni said.
As a follow-up, she plans to look at the hearts of the babies in the study when the children are 1 year old. That will help determine if the heart muscle abnormalities are lasting and, if so, whether they have become worse, she added.