[Solved] Different delta values in each process

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JordanMotta
:warning: Old Version Published before Godot 3 was released.

I have multiple rails. All rails start with process to false, and i have an AI very simple that each 2 seconds choose between 3 rails and set a train. When the train reach the end of the rail swap the train to another rail (This rail is dynamic and can be there like not) and here is where the “magic” happen. When the train has no reach the end yet the delta is 0.016, but when swap the rail to another the delta is 0.113 and this doesn’t happen to each process, just happen to the dynamic rail process. Have any idea why this happen? Sorry for the english.

**Edit 1: **

I found the solution but the problem wasn’t directly the delta. When the train jump from one rail to another i don’t dereference the train from the old rail so the process that calculate the position of the train was executed two times. Maybe this make the high delta value problems.

:bust_in_silhouette: Reply From: Zylann

All I can say is that your game is probably laggy. What you are doing at switching time is maybe a heavy operation (like loading, creation of lots of nodes or a big fragment of code, directly or indirectly) that makes the game hang for longer than a frame.
If you don’t think that’s a heavy operation, please explain what you are actually doing^^

Delta is not supposed to be always the same, that’s the reason why it exists and is passed to all process functions. You have to deal with it and update your code so it doesn’t break if framerate fluctuates.

When the game start, it load all the resource so i don’t think the resource is the problem. But when the train is in the dynamic rail i do this:

Globals.get(global.actives_rails).append(self)
print ("active rails: ", Globals.get(global.actives_rails).size())
set_process(true)
set_train (train)

and in process i do this:

func _process(delta):
if not has_train ():
	return
	pass
origin_pos = train.get_pos ()
destiny_pos = destiny.get_pos ()

var train_pos = train.get_pos ()
var new_y = train_pos.y - (delta * train.get_speed ())
train.set_pos(Vector2(train.get_pos().x, new_y))

I was thinking to use my own delta to keep the things stable, because the game is for one player.

JordanMotta | 2017-02-08 20:32

I don’t see heavy stuff here, but other functions are called, I can’t tell what’s going on. if you are sure delta is dropping exactly at the moment when you switch rails, follow all things you do at this moment and search what can cause the slowdown (printing, for example :p).

Zylann | 2017-02-08 20:54