0 votes
extends Camera2D

onready var player = get_node("/root/MainScene/Player")

func _process (delta):

    position.x = player.position.x
in Engine by (14 points)
edited by

1 Answer

0 votes

Note: I fixed your code formatting.

Your problem is due to the order in which nodes become ready. "MainScene" is not ready when the Camera2D node becomes ready, so that path is not valid yet.

See: https://docs.godotengine.org/en/3.2/getting_started/step_by_step/scene_tree.html#tree-order

by (21,930 points)

ok my camera should be ready last the way its lined up unless im misunderstanding how nodes load.

enter image description here

_ready() happens in reverse tree order. The camera is the first node to be ready. Then "Tile", then "Player", and finally "Mainsece". A parent is not ready until all of its children are.

Since Camera is ready first, its onready code runs. But since that code tries to access "Mainsece", it fails.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.