#Best way to implement manager/controller script for scene-to-scene transitions via doors?

5 messages · Page 1 of 1 (latest)

runic timber
#

Hello! I've been successful in creating a global audio manager/controller script that works great for managing my audio across scenes.
And, since that worked so well, I figured I would try my hand at creating a script for managing scene transitions for the doors in my game so I don't have to hardcode them for each individual door. Well, fast forward to today and I've hit a roadblock and could use some help! Any hints/tips to point me in the right direction would be greatly appreciated! 🙏

vagrant sapphire
#

What exactly are you trying to do? Like what do you want to do with the doors and changing the scene?

runic timber
#

Thanks for the reply. 🙂
I'd like to make it so I have a single script that controls all scene transitions between my doors. Right now I have scene transitions individually coded to each door, which is a very manual and laborious process.

vagrant sapphire
#

I guess, what you could do is make a global script with the scene transition function. It could take a custom variable to be able to change the path in the scene transition method. Then, since the script is global, you could simply call this function whenever you want and just have to add the exact scene you want to go to. It could look something like this:

#the script in the Autoload is called "SceneChange"
func change_scene(target_scene: String) -> void:
  get_tree().change_scene_to_file(target_scene)

#level script
func _on_DoorArea2D_body_entered(body):
  if body.is_in_group("Player"):
    SceneChange.change_scene("path/to/file.tscn")```
You absolutely don't want to have to figure out the path within the level file and want to do it within the one singular script? Then you would track the place of your player (in which room he is) and maybe also in which door he walks into, and have to add something to your global script to make it work. I imagine it would look like this:
```#global script
#the script in the Autoload is called "SceneChange"
var projected_room: int = 0

func change_scene() -> void:
  var scene_file: String
  if projected_room == 0:
    scene_file = "path/to/file.tscn"
  elif projected room == 1:
    scene_file = "other/path.tscn"
  get_tree().change_scene_to_file(scene_file)


#level script
func _on_DoorArea2D_body_entered(body):
  if body.is_in_group("Player"):
    SceneChange.projected_room = 1
    SceneChange.change_scene()```
I hope this will help you!
runic timber
#

Thank you so much! Will give it a whirl tomorrow.