In a medium saucepan, whisk together the granulated sugar and cornstarch.
In a separate bowl, whisk the egg yolks with the milk until smooth.
Slowly pour the milk mixture into the saucepan in several additions, whisking well after each addition.
Place the saucepan over medium-low heat and cook, whisking constantly, until the custard thickens and begins to boil, about 6–8 minutes.
Remove from the heat and stir in the butter and vanilla extract until completely melted and smooth.
Transfer the custard to a heatproof bowl and cover the surface directly with plastic wrap to prevent a skin from forming.
Cool completely to room temperature.
Fold in the whipped topping, if using, then refrigerate until ready to assemble.