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.
0 votes

Hello Godoters,
I have been creating a text game by following the tutorials on youtube(here is the link ) and I came to the point where I have to save the reusable scene by adding it to the GDScript here is the code:
extends Control

const InputResponse = preload("res://InputResponse.tscn")

onready var history_rows = $Background/MarginContainer/Rows/GameInfo/HistoryRows

func onInputtextentered(newtext: String) -> void:
var input
response = InputResponse.instance()

The problem is whenever I launch the game,the debugger pops up with the error message: attempt to call function ‘add_child ’ in base ‘null instance ’ on a null instance.

Godot version v3.2.2.stable.official
in Engine by (18 points)

2 Answers

0 votes
Best answer

A node doesn't exist at the node path Background/MarginContainer/Rows/GameInfo/HistoryRows at the time your control node that the script is attached to is _ready().

First try make sure that the NodePath listed above is valid.

If the NodePath above is valid and you are still getting the error, move the node that the script is attached to up in the scene tree so its _ready() function gets called later. Alternatively change your function, so you know that all nodes will be in the scenetree when you attempt to get them:

func _on_Input_text_entered(newtext: String) -> void:
    if not history_rows:
        history_rows = get_node("Background/MarginContainer/Rows/GameInfo/HistoryRows")
    var input_response = InputResponse.instance()

More about how nodes are added to the scenetree:

by (3,906 points)
selected by
0 votes

So when I "Copied Node Path" it copied everything but the root thing:

My root is named Control so I changed my code to:


And it worked! I hope this helps someone else.

by (22 points)
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.