Also found out you can generate the shadowMap once, and then remake it when needed by doing this.
const shadowGenerator = new ShadowGenerator(2048, sunLight)
// some settings I have found looks good
shadowGenerator.enableSoftTransparentShadow = true
shadowGenerator.transparencyShadow = true
shadowGenerator.filter = ShadowGenerator.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP
// render once at startup
shadowGenerator.getShadowMap().refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE
// if you move anything you can force it to render by calling
shadowGenerator.getShadowMap().resetRefreshCounter()