I've migrated my project to 4.0 and everything works - but there's now a big lag spike whenever the player enters a battle. This isn't present when running the game in 3.5.1, the game runs totally smoothly there.
Through trial and error, it seems that the block of text causing the lag spike is this one, where the players are added to the battle:
for i in PartyManager.playersInParty.size():
var newPlayerBattler = playerBattler.instantiate()
newPlayerBattler.myStartingPos = enemyBattleInfo.playerStartingPositions[i]
newPlayerBattler.playerInfo = PartyManager.playersInParty[i]
var facingDir = Vector2(0, -1)
newPlayerBattler.face_right_direction(facingDir)
newPlayerBattler.initialize(self, enemyBattleInfo.playerStartingPositions[i], centerOfBattleScene)
newPlayerBattler.global_position = enemyBattleInfo.playerStartingPositions[i]
newPlayerBattler.name = "P" + str(i + 1)
playersInBattle.add_child(newPlayerBattler)
var newActionWindow = actionWindow.instantiate()
newActionWindow.player = newPlayerBattler
actionWindows.add_child(newActionWindow)
newPlayerBattler.actionWindow = newActionWindow
newActionWindow.open()
var newTechWindow = techWindow.instantiate()
newTechWindow.player = newPlayerBattler
newTechWindow.hide()
techWindows.add_child(newTechWindow)
newPlayerBattler.techWindow = newTechWindow
No one particular line of code seems to be causing the problem, instead it seems like it's the combined effect of a large number of functions running at once that causes it.
Does anyone have any idea why this causes performance to suffer in 4.0, but not 3.5.1?
Here's a video of the lag spike, it happens just before the players draw their weapons and the battle windows appear:
https://webmshare.com/play/Y7qAV