Invalid get index 'zoom' (on base 'null instance').

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BCS
extends ParallaxLayer

@onready var camera = get_tree().current_scene.get_node("Player/Player/Camera2D")
@export var sprite_scale:int = 4
@export var y_mirroring:bool = false

var last_screen_size = Vector2()
func _process(_delta):
	var screen_size = get_viewport_rect().size * camera.zoom
	if screen_size != last_screen_size:
		var sprite = get_children()[0]
		sprite.scale = Vector2(sprite_scale, sprite_scale)
		var sprite_size = sprite.get_rect().size
		var rect = Rect2(0, 0, sprite_size.x * ceil(screen_size.x / sprite_size.x/sprite_scale),
		sprite.region_rect = rect
		sprite.region_enabled = true
		motion_mirroring = Vector2(rect.size.x*sprite_scale, 0)
		if y_mirroring:
			rect.size.y = sprite_size.y * ceil(screen_size.y / sprite_size.y/sprite_scale)
			sprite.region_rect = rect
			motion_mirroring.y = rect.size.y*sprite_scale
	last_screen_size = screen_size

I’m getting error on line 9 and also an error saying Node not found: Player/Player/Camera2D (relative to /root/World)

:bust_in_silhouette: Reply From: zhyrin

get_tree().current_scene points to a node, that node doesn’t have a grandchild with the path Player/Player/Camera2D, hence your camera variable gets assigned null.
When you are trying to read camera.zoom on line 9 you get an error because null type doesn’t have a zoom member.