Yes in most times they are paid up front, but if a game gets pirated en-mass, it’s the next round of developers that gets shafted in the end due to “downsizing” or “piracy remediation” or some bullshit like that.
The publisher then re-configures how money is paid the next round so they always profit, even at the cost…