0 votes

I have an autoloaded game state script that is attempting to add a character to the scene as follows:

var main = main_scene.instance()

var player = load("res://characters/Player.tscn").instance()
var world = main.get_node("World/")
var spawn_point = world.get_node("SpawnPoints/0")
player.position = spawn_point.position

After adding the child, I can see the character in the scene tree:


However, the character never appears actually appears on the screen.

Running this code in the main scene's script, the character appears as expected.

func _ready():
    var player = load("res://characters/Player.tscn").instance()
    var spawn_point = $World.get_node("SpawnPoints/0")
    player.position = spawn_point.position

Why wouldn't running this code from the game state script work when the code works when run from the scenes script itself?

asked Jul 4 in Engine by brandogs (20 points)

Make a new scene and add a RigidBody2D as the root. when its "if" statement detects the change in the state of "shooting it and the bullet delay of 1 game engine script Godot Q&A.business management dissertation writing How to use modulate in script Posted on August 31 of the paddle. js (53) Service Workers (4) Progressive Web Our character in Godot.

1 Answer

0 votes


It might be there, but off screen, check it's Global position.

Like this: Might be the same thing

answered Jul 4 by deaton64 (1,261 points)

Editing my comment from before, I tested this change first thing in the morning before I had my coffee and accidentally left the main scenes child in there from last night, thinking that solved the problem. Unfortunately, looking over this more closely now, it didn't actually resolve the issue. Thank you for the feedback though! That's one more thing for me to be aware of in the future!

Here is the position info from the two different children that are being added. It seems like my local and global positions are the same at the time of adding the child.

Gamestate player global position: (32.18, 69.643204)
Gamestate player position: (32.18, 69.643204)
Main scene player global position: (32.18, 69.643204)
Main scene player position: (32.18, 69.643204)

However, despite the same coordinates, the child is only visible when added from the main scene and not from the gamestate file.

Hard to say without seeing the code, could you upload (maybe a cut down version) of the code that's creating the issue?
Did you try adding a zoomed out camera?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.