How to fix Attempt to call function 'add_child' in base 'null instance' on a null instance error in Godot Engine 3.5?

Godot Version

Godot 3.5

Question

Hello to all, I need you to solve a question I have, why I get the error shown in the following image when I run my game from the main menu and how can I make the levels can also run from the main menu?

Thank you in advance!

If I’m not mistaken, this is related to get_node(…), because when trying to get a node, the method returns null. Maybe you have specified the node get wrong and you should check if the nodes are bound to each other. You can also try using get_parent, get_owner, get_child methods to get to the right node.
Short description:
get_parent gets the parent of the node
get_owner gets the topmost parent of all nodes, the root of the scene.
get_child gets the child node by its index, i.e. how it is located in the scene tree (top to bottom)

I keep getting the error, can you tell me how I should fix this error, please?

You are going to have to find out what is in node_data["parent"].
It clearly isn’t what you think it is (and we have no way of knowing) so try printing it out and see what it actually is.
print(node_data["parent]")
I am guessing its going to print null, so you need to find out why that dictionary entry is not getting written.

i see, save/load game, i always recommend using plugin, many people stuck with this save and load of the game
GitHub - AdamKormos/SaveMadeEasyG3: An easy to use, versatile Save/Load System for Godot 3 inspired by the simplicity of Unity’s PlayerPrefs. Supports nested variables, Resources, Arrays and encryption. here is for godot 3

the example implementation of the plugin is here File.open(path, FileAccess.WRITE) is not truncating - #7 by zdrmlpzdrmlp
but it’s in godot 4 script

also it seems like you are trying to save a whole node/scene data. is that necessary?

It is giving me a value that does not exist, in the console it says the following message: /root/Level1, level 1 is actually in the project folder, and that is where it should be loaded from or from the user folder, but not from the root folder, could you tell me how to do that? Because it is really not recommended to use plugins to make save and load game systems.

plugin just to help you quicker to what you need, always can modify the plugin script too to fit your purpose.

1 Like

Yes, it is necessary, because I need to save the player’s points, this player’s position and the player’s lives, but can that be done with the plugin you told me?

then just save the player points, position and lives data, no need to save whole running nodes of it

in the example implementation, i showed how to save the “slime” HP, max HP, global position. other variable can be just added too. without needing to save whole slime’s scene’s data

Oh, wow, I saw that all that was done in a YouTube tutorial, but now I don’t understand how I can save the character’s position without having to go to its root node?

use autoload singletons, But the plugin alrdy done that for you, just call the autoload script of SaveSystem

Where is the info on how to use this plugin?

you can download it from asset Library tab on your godot editor
search “save” and it should pop up for you, just download then enable it
click view files to see the official documentation of how it’s used, but if you want a pretty basic example of how to use it, check what i have sent following the plugin link

Be active and there it works alone? Although I do not think so, I asked him where is the information on how to implement it in the code? Ah, thank you very much!

pretty much what a plugin done for you, it serves what it’s said to serve, you just need to know how to use it.

tell here or dm if you have problem using it, saving game shouldnt be saving whole nodes data, only need to save and load crucial informations

One question, how can I define what things I want to save in the plugin script, I found an empty dictionary in the plugin script, but for example I could not access the exact position of the player by putting elements inside that dictionary.

you just throw in by SaveSystem.set_var("key_name",the_value)
remember to SaveSystem.save()
for every set var

Hello again, other question, why when I load the data saved in the file, only the points and lives are loaded but not the coordinates of my character? I need also to save those coordinates, because I did it as follows SaveSystem.set_var("x_pos", position.x) in my character’s script once the game window was closed (the same line of code I used for the y_pos and putting after the comma position.y), I really don’t know how to do that, because I saved all the necessary data you told me.

because the save files is saved in JSON, which mean saving vector will just become string, you will need to convert it back to vector2 by yourself when loading the position. so from string to vector2. some ppl made a conversion for it like https://www.reddit.com/r/godot/comments/4t25y1/string_to_vector2/

or simply you can just save the position in 2 “key” position x and y, that’s what i’ve shown in the example implementation. then when loading it, you put it in new Vector2 the x and y

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.