Get_parent works SOMETIMES

Godot version 4.3

For starters, I’ve only been using Godot for maybe a month. So, sorry if I come off as an idiot. Also, I’m aware this piece of code is an eyesore. So, if anyone has an idea of how to make this look better or more streamlined; I’m all ears.

The problem I’m having is that the highlighted line works and gets the correct node if I don’t call on that variable to get any information from the node (like how I have the line after checking if removed_slime’s exported variable “breeding” is true or not). If i do print(removed_slime) right after establishing the variable it does get the right node, but for some reason any time I use the variable, like the right after, it says it’s a null value?

Extra information: The scene this script is attached to is in the main scene, just has visibility turned on and off while signals are being emitted and connected to trigger this function to run. So, I don’t think the hideous train of get_parent()s is being affected.

Again, sorry if I sound like a moron, but I’ve been working on just this problem for going on three days now and I think I’m too deep to really think about a solution.
Any help or tips is very much appreciated.

2 Things:

  1. Can you send us a picture of your scene tree?

  2. You can use the get node format to shrink this line (get_node("../../../../../../../../slime_name")). If you are referencing the same node multiple times and you create it in the editor, you can use unique names to clean this up. If you are creating it in code, create a constant or variable that contains a reference to that node upon creation so that you don’t hae to grab it later.

1 Like

home scene tree
This is the home scene, but by clicking Breeding_Den_Base it instantiates a menu that is a child of it. And then by clicking within that menu it toggles the visibility of the left and right slime menus at the bottom of this screenshot.
Den menu scene tree
The slime menu scene tree is below.
slime menu scene tree
And then there’s the slot scene that is a child of the VBoxContainer which is below.
slime slot scene tree
And the script that I’m having the issue with is the one attached to the slime slot scene.
I’m sorry this all seems so messy compared to any other questions I’ve seen on here x.x

And am I right to assume the “…/” part of that code is the same as get_parent()?
I’m pretty sure this is the only time I’ll be calling for this specific node this way, but thank you for the tip about the editor.

It sounds like you don’t want to be getting great-great-great-etc grandparent. Can you run your game, select the “remote” scene tree view and mark where the script starts, and what node you would like to get? I think you want to get a deeply nested child node?

1 Like

Oh, I didn’t even know remote view was even a thing x.x. Thank you for that. It’s actually so helpful.



The first screenshot shows the scenes from which the script is being ran and the second one is the nodes from which I’m trying to access information from based on their name. They’re not a child of the scene from which I’m running this specific script. They’re a child of the “Home” node which is however many great-grandparents away of the script scene (slime slot scene).

1 Like

Maybe you could get them by current_scene or /root/Home/ since they are so close to root.

var removed_slime = get_tree().current_scene.get_node(slime_name)
var removed_slime = get_node("/root/Home/" + slime_name)
1 Like

Another thing I didn’t know was a thing :sweat_smile: current_scene. What a life changer lol. Thank you for that.
This does work reliably to get the node even when using the variable to get information about the node the variable gets.
Maybe the train of get_parent() was causing some issue down the line?

Though, this caused me to stumble into the same original problem I was having that caused me to implement this code to try to solve. It deals with the same function, but is technically a different question. Should I make a new post about it or would it be okay to continue it here?

This issue? We can continue here. It could be queued for deletion, still a valid non-null object, but it’s properties should not be modified. I noticed this variable is named removed_slime, do you call queue_free() on it before this function is called?

No, that was the problem with my train of get_parent() that somehow grabbing the node from current_scene fixed.
The original problem was editing the exported variable of the node that I’m grabbing.
I’ve tried a few different things and I think this is the right direction (getting the node by name), but for some reason I’m still not able to edit the variable (the breeding variable).
Screenshot 2024-10-15 103849
This is a screenshot of the same function as before (attached to the slime_slot scene) with the one before it because it works in as far as editing the same variable (breeding) of the same scenes (the slimes). This function turns the breeding variable on, but the second function I’m trying to turn it off if it is on. (I’m sorry if this all sounds like word soup x.x). I know that slime’s breeding variable is on because it’s toggled on and never toggled off, but for some reason the “if removed_slime.breeding != false:” part doesn’t trigger to complete the function?

Screenshots of all of the slime’s script if needed vvv


how is breed_slime called? No errors?


I honestly have no idea how the breed_slime function works in as far as accessing the slime’s information (it was the first thing I tried and it worked so I left it) and I think that’s why I’m having this problem now.
And if you’re asking if the _remove_leftslime function has errors; no, it doesn’t the way I have it written in the previous screenshots before this reply. Though, I’ve been messing with it to try to fix it and I do get the “null instance” error if I modify it to not have the if statement (I believe this is the same error I was getting before when I was using the get_parent() train).
Screenshot 2024-10-15 150721
:woman_shrugging:
Learning Godot was going so smoothly until I hit this problem and now I feel crazy :sweat_smile:

It sounds like you are removing the slimes_slot and/or changing scene then. You should run through the stack trace it gives you and find out when you delete such a thing.

1 Like

Oh wow, obviously :skull: Yeah, my slimes_slot scenes are being cleared and updated at certain times to show updated variables of each slime. I don’t know why that didn’t occur to me to not run this function in the slimes_slot scene’s script. I moved the function to be in the slime_menu script which isn’t, itself, being updated and I’m not getting any more errors, but for some reason it’s still not editing the slime’s variable. I’m sure if I just keep tinkering with it I can get it to work now, but do you maybe have any ideas why its not working?
Screenshot 2024-10-16 154549

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