Hello,

I have a scenes/gui.xscn

GUI -- Menu -- TextBox

I have a scenes/room1.xscn and inside it, i import my GUI, my player etc. The player can move, walk to room2, come back to room1, and the gui is visible and my test button to exit the program is clickable, so i think it's fine. But when i want to open the menu for example, Godot says the node can't be found. I tried different ways like :

get_node("/root/Menu") get_node("/root/GUI/Menu") get_scene("res://scenes/gui.xscn").get_node("/root/Menu") ... and some others

Help ?

I made a mistake understanding my problem.

It was fine, mostly based on Genfy's video /channel/UC7vsIJl_Hb7QNeioDPM5kSg

Until i move the player and the gui in their own scene for further development.

I have a scene for room1 and in the room1 there is a sign (a StaticBody2D with a Node2 to trigger interact) I have a scene for my gui and i import it inside room1 I have a scene for my player, and when player interact with sign, the text should be displayed in the gui.

So know i have to figure how to reassemble the puzzle.

I sort of said this in your other thread, but after reading this thread I'll say it again more strongly: Stop using the /root node. It's a pain in the butt to deal with because it doesn't exist in the editor and you don't have any control over it. Make a "World" scene instead and use that.

I think it would help you at this point to get out a piece of paper, make a list of the different main elements in your game, and draw a diagram of how they will be organized. Think about which things are changing all the time and which things stick around. Actually, I'll do some of it for you here:

Most games have a main menu that is totally separate from the actual game. So you probably want two main scenes: Menu, and World. Everything in your game will at some point be a child of one of these scenes. Menu will be the default scene that's loaded when someone launches your game. In the menu you'll probably have a Play button that calls get_tree().change_scene("res://World.tscn"), loading the World scene and starting the actual "game" part of your game.

The World scene will have a bunch of things(scenes) inside it. Some of these scenes will be more or less constant for the whole game session, some will come and go all the time.

  • Room - changes - each room contains the walls, obstacles, enemies, goodies, etc.
  • HUD - always sticks around
  • Player - sticks around until it dies

The room scene will change often, so you don't want to give it any children that are supposed to stick around. Walls, enemies, and stuff will be children of the room, since they should come and go with the room.

The player, even though he's "inside" the room, probably shouldn't be a child of the room scene, since he sticks around from room to room.

Changing Rooms: The code for this should be in a script on your World scene or maybe on a "Room Manager" node inside that, if you want things organized in smaller chunks. To change rooms, simply free() the current room, then load() and instance() the new room scene and add it as a child of the World(or Room Manager node).

When the room changes, the player will need to "teleport" to a new location depending on which door he entered through. So your Room Manager needs to remember which door you exited the last room from and use that info to figure out which door you enter in the new room. How exactly you do this is another discussion. The exact position of the door in the new room will probably depend on the room, so each room scene will have a function like get_room_pos(door), which returns the position of the specified door when called. The Room Manager just calls get_room_pos(door) for the door it wants, and moves the player to that position.

Room change done.

Thank you for your precious advices, here and there.

/em shakes brain to connect neurons

@Tchey said: Godot says the node can't be found.

You question needed more info, i didn't understand it when i first saw it. I think you have a pathing issue at hand. The key thing is where is your script?

say you have: Main -item -player(script)

From "script" on player: To get to item you would do get_node("../item"), or get_node("/root/Main/item"), or get_tree().get_root().get_node("Main/item"), or get_parent().get_node("item"), etc. You get the idea. The last one gives you autocomplete which is great so maybe its preferable.

Generally if autocomplete isn't there, likely you are doing something wrong. :smiley:

22 days later

Hi again, i think i lost my brain again.

So i have univers.xscn with

Univers (a Node2D) -- Player (instance) -- GUI (instance)

I have a gui.xscn with

GUI (a CanvasLayer) -- TextBox (a Patch9Frame) ---- EventLog (a RichTextLabel)

i have a unit.xscn with different labels like life and mana

I have a encounter.xscn that will handle a basic fight like FireEmblem

I instance this to my unit to check if player and unit meets : go_to_encounter.xscn with

Area2D (+script) -- CollisionShape2D

The script :

extends Area2D

func _on_Area2D_body_enter( body ):
	print ("Encounter !")
	get_node("GUI/TextBox/EventLog").add_text("Test : Encounter !")

So why get_node() returns an unknown path ?

I don't have any computer/programig stuff background at all. The "structure mind" is the most problematic part in my progress, i need to learn and i feel stupid to not getting it yet... but it would be more stupid not to ask again.

(edited :

OK, i didn't want to use /root as advised, but eventually i got it done with this line

get_node("/root/Univers/GUI/TextBox/EventLog").add_text("Test !\n")

6 years later