In a medium saucepan, heat the milk over medium heat until it begins to simmer.
In a bowl, whisk together the sugar, egg yolks, and cornstarch until smooth.
Gradually add the hot milk to the egg mixture, whisking constantly to temper the eggs.
Return the mixture to the saucepan and cook over medium heat, stirring constantly.
Continue cooking until the mixture thickens and begins to bubble.
Remove from heat and stir in the butter and vanilla extract.
Pour the pastry cream into a bowl and cover with plastic wrap, pressing it directly onto the surface.
Let it cool at room temperature for about 30 minutes.
Refrigerate for at least 2 hours before using.
Whisk the cream gently before using to restore its smooth texture.