Last active
May 20, 2021 05:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can add
and not "pin" in scene_node
for example to theif
statement wherevar pin
is added to scene scripts where you don't want the centering to take place.