Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
682 views
in Technique[技术] by (71.8m points)

Godot: get_node: Node not found: /root/MemoryGame

So, I'm new to Godot and made my first two projects. The first one is a Platformer game, the 2nd one is a Memory Card Game. Both games work fine when I run them separately. Yesterday, I got an idea to put the Memory Card Game into the Platformer Game, so when I interact with some NPCs or enemies the Memory Game will launch as a mini-game. But...

When I try to run my Platformer Game with the Memory Game inside and click a card I get an error: "get_node: Node not found: /root/MemoryGame" I think the problem is this code in my "Card.gd": "get_node('/root/MemoryGame').chooseCard(self)" .

Here is a short video to show you the problem: https://youtu.be/skAzwJE_O-0

So it seems like the main platformer game scene (Level1) cannot find the "MemoryGame" file or any of its children. I even tried to autoload the MemoryGame file but it didn't help.

Card code MemoryGame code

question from:https://stackoverflow.com/questions/65860520/godot-get-node-node-not-found-root-memorygame

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you run your "MemoryGame" the root / will be the root of the current scene which is the memory game's root, and when you add the MemoryGame scene inside your platformer, the root will be the platformer's root. In that case, using an absolute path ('/root/MemoryGame') won't work, use a relative path

get_node('..').chooseCard(self)

for more see scene tree and node path


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...