Help me Attempt to call function 'instance' in base 'null instance' on a null instance.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DanniloSN
:warning: Old Version Published before Godot 3 was released.

I need help with a script instances, here the code:

#Script instructions
extends Node
var currentScene = null
var PlayerName = "Mike"

func _ready():
   currentScene = get_tree().get_root().get_child(get_tree().get_root().get_child_count() -1)
   Globals.set("MAX_POWER_LEVEL",9000)

func setScene(scene):
   currentScene.queue_free()
   var s = ResourceLoader.load(scene)  #ERROR HERE ERROR HERE
   currentScene = s.instance()
   get_tree().get_root().add_child(currentScene)
   
func getPlayerName():
   return PlayerName

# Script call
extends Node

func _ready():
	set_process(true)

func _process(delta):
	if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
		get_node("/root/global").setScene("res://Scenes/in_game_bot")

Edited by moderator: Please use code formatting (see the “{ }” button).

Did you double check that this path and filename is correct? “res://Scenes/ingamebot”

atze | 2016-07-26 06:29

am getting the same error but on the s.instance. Please help.

Attempt to call function ‘setScene’ in base ‘null instance’ on a null instance. (Error)
showing this error at :

get_node(“/root/global”).setScene(“res://SecondScene.scn”)
and i also tried, get_node(“/root/global”).setScene(“res://SecondScene.tscn”)

yeeshu06 | 2017-02-20 11:02

:bust_in_silhouette: Reply From: splite

Can you please try to add file extension on your res:// path: get_node("/root/global").set_scene("res://Scenes/in_game_bot.EXTENSION") (like .xml, .scn etc) and tell us if it helps? :slight_smile:

You are sending file path (from “res://” space), not node path.

Example: get_node("/root/global").set_scene("res://Scenes/in_game_bot.scn")

Btw, i think you was going thru this tutorial on changing scene. That guy is using get_node("/root/globals").set_scene("res://Scenes/game.scn") - first is node path, second file path.

worked , thanks man, but I wanted to do to change screen When you press a “button” in the first scene , I tried to use " get_node (node ​​) .is_pressed ()" but did not work

DanniloSN | 2016-07-26 12:53

Look for connect, actually it is explained in Part 5, section “Connecting Code to your Control”.

splite | 2016-07-26 13:37