Godot Version
4.2.1
Question
so i tried to add a scene into another scene for the game im making but everytime i try to run the game the error is: “attempt to call funcion add child in base null instance on a null instance”. Can anyone help? Here is the code:
func xp_bar():
var xpbar = $"../CanvasLayer/xpbar"
xpbar.value = global.player_xp_gain
if xpbar.value >= xpbar.max_value:
global.counter += 1
global.player_xp_gain = 0
print("level ", global.counter)
xpbar.max_value = 100 * global.counter
var options = 0
var options_max = 3
while options < options_max:
var option_choice =item_option.instantiate()
upgrade_options.add_child(option_choice)
options += 1
also forgot to say that the function is put into ready func…
1 Like
Could you maybe show the scene tree wity the added scene?
here it is! that is for the scene that adds itself to the other one.If you need anything more just tell me
Hmm, could you send me the other scene tree as well? The one with the added scene. Maybe helps with problem declaration
here is also the script for the first screenshot i sent you if you need the variables
To be honest, I don’t really see why this is going wrong, I will try to replicate a similar script/setup and maybe I see something
I eill tell you if I found something after doing that
So I looked through some other scripts I have written so far and I think the Issue is inside the script where you instatiate the scene. You might have forgotten to add something crucial in there. Would you please send the main script?
hey sorry for taking so long i have been in school. what do you mean by main?This first script that i have sent in the opening message was in the player script which i would consider main cuz most of the features are there. I can send you the varibles of the opening script if you need that

here are all of my scripts.Which do you consider as main?
and here are the variables
If Panel
is not the root of the scene you need to do World/Panel/
, get_tree().get_root()
doesn’t return the root of the scene, but the viewport of the game
i typed @onready var upgrade_options = get_node(“levelup/Panel/upgrade_option”) and it still was saying the same error.I dont know if you wanted that or not but that doesnt work
You haven’t shown the hierarchy where it is so I can’t tell what’s wrong, please show where that node is
But where is it in the whole scene, you’re not showing where item_options
is
item options is the scene and its used for the instantiate
Yes, but where in the scene you’re calling it from, where under World
, that’s what matters here