This is how I do it too. You have to have the line down so cold you could play it in your sleep.
Then, when I practice the vocal, I start out just playing one note from the bassline on the upbeat of each measure, then add notes as I get the melody together.
It helps me if I can recognize where the melody notes belong in relation to the bassline.
Eventually it all comes together. It also helps if you have a drum machine too
