Custards can be grainy due to a number of factors. First, the eggs could be overcooked, leaving bits of scrambled eggs in the custard. Also, make sure the chocolate is fully melted before chilling. Plus, if your recipe calls for butter, it must be whisked in thoroughly so there are no bits left unincorporated.