I just built a rather large setpiece for my game that should be accessible at certain times. Loading the scene is fine, the file is great but during scene changes I am getting a "null pointer" error and I am having tried abstracting, loading and preloading the scene to no avail whatsoever. Help is appreciated. I am on the most stable/recent branch of Godot 3.5. My scene is supposed to change after a small animation in instanced and resolves.

extends Node2D

## flags and file references
var _canRun = false
export var _isExit = false ## if exit, show exit prompt
export var _myDestination  = preload("res://scenes/se_tower/SecurityCenter.tscn")
var _stageTarget = ""
export var _myEventKey : String = "rgbmaze" ## this key for permanence
export var _unlockKey : String = "rgbopen" ## to "open" scene
var _curtain = preload("res://background/surreal/ScreenDrop.tscn")
onready var _bgm = $AudioStreamPlayer2D



func _ready(): ## check for event and chase status before going live
	if !_isExit: ## if exit, it's always here
		if !DirectorNode._eventLogArray.has(_unlockKey):
			self.queue_free()
		else:
			if DirectorNode._eventLogArray.has(_myEventKey) or DirectorNode._chaseMode == true:
				self.queue_free() ## free if enemy or rgbmaze visited already
			else:
				randomize() ## 1 in 3 chance to appear
				var _d6 = randi() % 6
				if _d6 > 3:
					SoundManager._stop_music()
					_bgm.play()
					self.visible = true ## reveal event (editor twiddling)
				else:
					self.queue_free() ## disappear if die roll lost



func _enterNightmare(): ## listen for input
	if _canRun:
		if Input.is_action_just_pressed("_interact"):
			SoundManager._stop_music()
			_create_curtain() ## create drop for brief pause before scene change



func _on_Area2D_body_entered(body): ## event can be called if player present
	if "Lydia" in body.name:
		_canRun = true


func _on_Area2D_body_exited(body):
	if "Lydia" in body.name:
		_canRun = false


func _process(_delta): ## listen for input, update prompts
	_enterNightmare()
	
	if _canRun:
		if _isExit:
			$ExitPrompt.visible = true
		else:
			$EnterPrompt.visible = true
	else:
		$EnterPrompt.visible = false
		$ExitPrompt.visible = false
	
	
	if DirectorNode._chaseMode or DirectorNode._enemyPresent:
		_canRun = false ## error handling, hides if not freed on enemy presence



func _create_curtain(): ## create curtain and connect scene change to exit signal
	DirectorNode._freezePlayer = true
	$Cue.play()
	var _inst = _curtain.instance()
	var _parent = get_parent()
	_parent.add_child(_inst)
	_inst.z_index = 0
	_inst.connect("tree_exited",self,"_dreamSequence")


func _dreamSequence(): ## set destination and change scene when screen resolves (this connects to my animation object)
	DirectorNode._destTarget = 7
	var _scene = get_tree().change_scene_to(_myDestination)

And here's the object it connects to for the change.

extends AnimatedSprite



func _ready(): ## lock in position
	self.global_position = Vector2(512,288)


func _on_StaticScreen_animation_finished():
	pass
  • xyz replied to this.
  • Aw rats. I figured it out already. My load was at the wrong place in code.
    Changed my load to where the event "appears" or occurs rather than the animation and its working fine now. Obvious advice of the day: where you put load makes a difference.

    SnapCracklins You didn't specify where in the code is the error thrown or which reference is null.
    It'd probably be best to post a minimal project that exhibits the problem.

      Aw rats. I figured it out already. My load was at the wrong place in code.
      Changed my load to where the event "appears" or occurs rather than the animation and its working fine now. Obvious advice of the day: where you put load makes a difference.

      xyz it was the scene itself (the one I wanted to change to). I just had to load it a bit sooner. All good now.