0 votes

Hi everyone. :)

I'm once again asking for some of your wise guidance. I'm following the tutorial, but eh yah, as a newbie I suppose it's easy to make mistakes.

I get this "node not found" error. I've tried to solve it on my own, I did notice a few spelling mistakes I had made and corrected those. But this that it can't find the node, I don't know how to fix that. In the tutorial "Code Your First Complete 2D Game with Godot" I'm at timestamp 40:20.

I have looked over connections, the timer, the scene tree itself to make sure things that are subgroups/children are correct. When I press F6 here I just get a white screen, no mobs moving around.

Here's the error message, and the code.

E 0:00:01.709 getnode: (Node not found: "MobPath/MobSpawnLocation" (relative to "/root/Main").)
<C++ Error> Condition "!node" is true. Returned: nullptr
<C++ Source> scene/main/node.cpp:1325 @ get
node()
Main.gd:10 @ onMobTimer_timeout()

    extends Node

export (PackedScene) var mob_scene

func _ready():
    randomize()


func _on_MobTimer_timeout():
    var mob_spawn_location = $MobPath/MobSpawnLocation
    mob_spawn_location.unit_offset = randf()

    var mob = mob_scene.instance()
    add_child(mob)

    mob.position = mob_spawn_location.position

    var direction = mob_spawn_location.rotation + PI / 2
    direction += rand_range(-PI / 4, PI / 4)
    mob.rotation = direction

    var velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
    mob.linear_velocity = mob.linear_velocity.rotated(direction)
Godot version V3.4.2
in Engine by (20 points)
edited by

1 Answer

+1 vote
Best answer

It'd be super helpful if you could highlight all the code and click on the curly braces. Just makes it more readable when it's nicely formatted and easier to see the issue.

The error tells you what failed and why:

get_node: (Node not found: "MobPath/MobSpawnLocation" (relative to "/root/Main").)

That's this line:

var mob_spawn_location = $MobPath/MobSpawnLocation

The $ symbol is a gdscript shortcut for the "get_node" function, precisely equivalent to get_node("MobPath/MobSpawnLocation")

Godot can't find a node called that there. The relative to "Main" is important, you start from the node you're on.

When the game is running on the top left panel it says "remote" and "local", it'll be currently set to local. Change that to "remote" and take a look. "Remote" shows the node tree as is in the current game. You can expand the nodes under "Main" and see if there's a "MobPath" and then expand that and see if there's a "MobSpawnLocation" (there isn't, but maybe you spelt it wrong).

It's probably a Node2D you were supposed to make earlier in the tutorial so if it's not there then go back to where it was added and see where you went astray.

Hopefully that will put you on the right track.

by (2,154 points)
selected by

Thanks for the answer!

I did click that "code sample" button when I added my code. o.O So a bit confused why it didn't work properly.

Well I think I solved it, not sure. I watched that bit of the tutorial again and noticed I had accidentally made MobPath a child of ColorRect and not of Main. So I changed the MobPath to be a child of Main, as it is in the video.

I also checked what you said, went into remote. There is a MobSpawnLocation in remote, should there be? The only difference between my "local" and "remote" is that remote has "root" at the top.

I'm not getting any more errors about MobSpawnLocation. Instead I now get another error related to line 13 and 22.

"W 0:00:01.046 The local variable 'velocity' is declared but never used in the block. If this is intended, prefix it with an underscore: 'velocity'
<C++ Error> UNUSED
VARIABLE

Main.gd:22
"

No worries, you can always go in after and edit.

"I had accidentally made MobPath a child of ColorRect and not of Main" - yup, that's your issue for sure. You told Godot there was a node in a certain place and there wasn't. As the old saying goes: computers are like old testament gods; all rules and no mercy.

"Remote" is a super handy tool so I'll take a moment to explain it for you. "Local" you'll be used to: it's the tree you're used to dealing with and shows the node tree before the game starts. The thing is, this can change when the game is running - objects can be spawned and deleted; eg. if you kill an enemy or a gun fires a bullet. "Remote" lets you see what's actually in the tree while the game is running. I didn't know if Nathan at GDQuest had spawned objects in runtime which would have meant the tree while the game was running might be different. Hence telling you to check remote and not just rely on local.

If ever you're coding and want to see what objects are in currently your game and what values they currently have, pop over to remote and take a look to see the situation live in runtime.

The velocity thing isn't an error, it's just a warning. There should be a yellow triangle. It just says you have a variable called "velocity" that you're not using. This line here:

var velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)

Looks like this should be handling movement but you're definitely going to have use it at some stage, I assume it comes into play later in the tutorial.

Alright I see, thanks for the info. :)

So two questions, should my "remote" be empty?
I just noticed in remote "autostart" was not clicked/ticked. Shouldn't remote be a copy of local or? And now when I press F6 autostart unticks itself. Above it I got a yellow text saying "changes may be lost!"

Also after this code in the tutorial he presses F6 and he says that the mobs can already spawn and fly around etc. Nothing happens when I press F6, just a white window and that var velocity warning.

And lastly one thing that bugs me. I have used a RidgidBody2D, just like the tutorial. However when I click inspector there is no "PhysicsBody2D" in that list. Which there is in the tutorial.

Remote is your node tree during runtime. It's never empty. It'll be a copy of local unless you spawn / delete nodes in runtime - something practically all games do.

F6 runs the scene you're currently on (as per tab above viewport). He might have been on a different scene, don't know.

Again, haven't seen the vid, but you sure it's not a KinematicBody rather than a RigidBody? It says what it is at the top of the inspector, in the scene tree the RB icon is a beachball and the KB is a running man.

Yup I'm sure the tutorial is using a RigidBody2D. Which has me baffled why it has some extra functions in the inspector and I do not.

Alright so I should not delete or really touch Remote, okidoki.

Here are some screenshots. The first two are from the tutorial on YouTube.
Second two are from me.

The last screenshot is from the tutorial and it's what I'm having issues with. This spawning monsters randomly code, does not work for me. I have retraced my steps a lot, looked through the tutorial several times. Kinda lost at the moment.

And I continue to have the warning with this code. When I press F6 at the main scene, the game minimizes and I'm directed to this code.

    var mob = mob_scene.instance()

enter image description here

enter image description here

enter image description here

enter image description here

Ah, ok. Honestly, not sure. Maybe just different versions of Godot. Don't know.

With the monsters not spawning. You need to debug, there's nothing obvious wrong with the code you've shared. Trick is to narrow down what it could be until you have the exact issue by a process of elimination.

So, check if _on_MonTimer_timeout is firing by added a print("firing") statement. Next, check that the mob is spawning. Here, you can use "remote" for that, see if it appears.

Check the mob's position is sensible and not six squillion on the x or something. Again, remote will show you (or you can print). Check it's moving, print(mob.linear_velocity)- you get the idea.

Keep chipping away and you'll find the issue. Stick with it!

Just an update, got it working now. :D

Decided to just start from scratch, and now it's working. I have learnt a lot.

Curios though, can using your own assets cause problems?

On my first attempt to follow the tutorial I tried using my own items, like my own png files for the mobs and player.

I don't know if that is what caused some issues. I have no idea if you need to, I don't know, "prepare" an image before you use it in GoDot. Or you can just add images however you want.

Well everything is working now, hehe made my own little game. :3 ^^

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.