In my case the issue was that I was using the legacy Text game object. Use TextMeshPro instead, it's better and works out of the box.