Hmm, definitely not what I would expect to happen looking at the code. Can you by any chance just call fuel_cell_visible
without call_deferred
? I do not know if that would help or not, but it might be something to try.
I looked around a bit on the internet and couldn't find any solutions. The only thing I found was using yield
, but I'm not sure that will be helpful in this case. This is more of a workaround that a proper solution, but you might be able to get around the issue by restructuring your code so that the position is set in fuel_cell_visible
. For example:
func fuel_cell_visible(player_object_data=null):
if (player_object_data != null):
player_object_data[0].global_position.x = player_object_data[1]
self.visible = true
$AreaPickUp/CollisionShape2D.disabled = false
yield (get_tree().create_timer(0.10), "timeout")
$CollisionShape2D.disabled = false
func _on_Player_fuel_cell_release(positionx_global):
var player_object_data = [self, positionx_global]
call_deferred("fuel_cell_visible", player_object_data)
That way the timing of fuel_cell_visible
shouldn't mess anything up, since it is also setting the position. Though as I mentioned, this is more a workaround than a proper solution.
The position on the X axis should be set before the call_deferred
, as call_deferred
should delay the execution of the function. Are you setting the position somewhere else in the code? Maybe that is interfering with _on_Player_fuel_cell_release
setting the position.