UI scaling strangely when I instantiate it

Godot Version



I made a pause menu a while back that worked for instantiating an overlay scene, which works just the way I want it to, so I copied the code for that screen over to give myself an option for a second menu:

var playerMenu = preload("res://Menus/PlayerMenu.tscn")

func _input(_event):
	if Input.is_action_just_pressed("ui_cancel") and get_tree().paused == false:
		get_tree().paused = true
		var pause = pauseScene.instantiate()
		pause.global_position = Vector2.ZERO
	if Input.is_action_just_pressed("ui_accept") and get_tree().paused == false:
		get_tree().paused = true
		var stats = playerMenu.instantiate()
		stats.global_position = Vector2.ZERO

However, when the new menu gets instantiated, the scaling is completely wrong. This is what it looks like in the engine, and it scales perfectly well if I load just that scene (including everything selected to show the margin containers)

But when I try to instantiate the engine using the code from before, everything ends up shrunk down, the margins lose their scaling, and the black background is now off-center. I’ve confirmed that the anchors on the second menu are scaled to the viewport, same as all the rest of the scenes.

Anyone have any idea why this might be happening?

This is what it looks like when instantiated inside another scene:

Can you post your node hierarchy?

Is the scene being instantiated as child of a container? Those will set the scale property of the Control node back to 1,1.

It was not! I was able to solve the issue by instantiating the UI as a child of a CanvasLayer (which also simplified a bunch of other settings I had needed to tweak to get the rest of my UI showing up properly).

1 Like