Firstly, don’t get side tracked into taking it out or messing with the hydraulics, motor etc. If they weren’t fine it wouldn’t operate on ignition only.
Your problem is purely sensor or roof ECU control related. I assume with engine running it won’t even unlatch, so I would maybe consider if the windows are an issue.
Does it make a difference with engine running but both doors open (if the doors are open it doesn’t need to do the short window drop, so this may allow the sequence to continue past the issue that’s stopping it)
Secondly. If the roof is stopped mid position and then the engine started, will it continue to open or close ?
Please clarify if it’s in unlatching or not before I go any further.