0
\$\begingroup\$

I'm having a problem with change_scene_to_file in Godot 4. For some reason after the scene transition succeeded, I was automatically transported back the previous play state.

Here is the video of my problem : https://drive.google.com/file/d/1oC1mx1tqMEnfH9ovZAjP_d6DI60xODji/view?usp=sharing

I use the same code for change_scene

from inside the house to outside:

extends Area2D var entered = false func _on_body_entered(_body): entered = true func _on_body_exited(_body): entered = false func _process(_delta): if entered == true: if Input.get_action_strength("enter"): get_tree().change_scene_to_file("res://Levels/game_level.tscn") 

from outside to inside the house:

extends Area2D var entered = false func _on_body_entered(_body): entered = true func _on_body_exited(_body): entered = false func _process(_delta): if entered == true: if Input.get_action_strength("enter"): get_tree().change_scene_to_file("res://Levels/inside_house.tscn") 

If I go from inside_house to outside it works just fine, but the other way it starts to have this problem.

How do I solve this?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is it possible that when you enter the house, you're still standing in the trigger area for the exit door, and the button to activate the door is still pressed? You might need to detect only new presses this frame, or move your spawn position/trigger area apart to break the cycle. \$\endgroup\$ Commented Oct 24, 2023 at 13:01
  • \$\begingroup\$ at first I thought that too, so I then drag the character out, far away from the trigger area, I aIso scaIe down the coIIision shape, but then the probIem stiII remain the same I have no idea why \$\endgroup\$ Commented Oct 25, 2023 at 13:35

1 Answer 1

0
\$\begingroup\$

You're checking for user input in _process(), which is executed every frame. It's possible that the interaction key is not released before reading user input during the next frame (when you're in the indoor scene). Therefore, the undesired transition takes place as well, taking you back outdoor.

Try to detect the key press only for the current frame by using Input.is_action_just_pressed() rather than Input.get_action_strength().

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.