This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

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)

func setScene(scene):
   var s = ResourceLoader.load(scene)  #ERROR HERE ERROR HERE
   currentScene = s.instance()

func getPlayerName():
   return PlayerName

# Script call
extends Node

func _ready():

func _process(delta):

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

in Engine by (19 points)
recategorized by

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

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 :

and i also tried, get

1 Answer

+2 votes
Best answer

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? :)

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.

by (241 points)
selected by

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

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

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.