Call up a subviewport from another scene

Godot Version

v4.7.1

Question

I have a scene that is a settings menu. All of it sits inside a subviewport in the settings menu scene.

I am now trying to setup my Main Menu in another scene.

How do I call the subviewport settings menu to display in my Main Menu scene?

There is a “Settings” button in the Main Menu scene ready to go, I just can’t figure out what to write in it’s script to call the setting menu scene’s subviewport.

The reason these menus are separate scene is that one will also be able to call it up from the pause menu in game.

Hi, just add it to your Main Scene.

Create a SubViewportContainer in the main menu, leave it empty.

@onready var ViewportContainer: SubViewportContainer = $SubViewportContainer

func _ready() -> void:
	var subviewport = SubViewport.new()
	ViewportContainer.add_child(subviewport)
	var scene = preload("res://settings_menu.tscn")
	var instance = scene.instantiate()
	subviewport.add_child(instance)