Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | unskilledmoss |
extends Camera2D
onready var player = get_node("/root/MainScene/Player")
func _process (delta):
position.x = player.position.x
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | unskilledmoss |
extends Camera2D
onready var player = get_node("/root/MainScene/Player")
func _process (delta):
position.x = player.position.x
Reply From: | kidscancode |
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: Using SceneTree — Godot Engine (3.2) documentation in English
ok my camera should be ready last the way its lined up unless im misunderstanding how nodes load.
unskilledmoss | 2020-05-23 22:54
_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.
kidscancode | 2020-05-23 23:29