Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Last active May 20, 2021 05:24
Show Gist options
  • Save andrew-wilkes/fdd218576e267f845e2c9c3a7fb0c554 to your computer and use it in GitHub Desktop.
Save andrew-wilkes/fdd218576e267f845e2c9c3a7fb0c554 to your computer and use it in GitHub Desktop.
Center the scene on the screen when not main scene in Godot
# Add to main autoload file
func _ready():
# Check the last child node of the root
var scene_node = get_node("/root").get_children()[-1]
if scene_node.filename != ProjectSettings.get_setting("application/run/main_scene"):
var property = "position"
if scene_node is Control:
property = "rect_" + property
set(property, get_viewport().size / 2)
@andrew-wilkes
Copy link
Author

You can add and not "pin" in scene_node for example to the if statement where var pin is added to scene scripts where you don't want the centering to take place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment