Node not found while running game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Riri

I have a question, I have a game and inside the game I have created some scenes like for example:
a Node2D ( that contains a KinematicBody2D and other stuff)
So I named it “MovingPlatform” ( the Node2D type) and Platform ( the KinematicBody2D).
In this case, in my code script in MovingPlatform I used onready var platform = $Platform.

I use a tween to move the platform.

func _ physics_ process (delta) :
platform. position = platform . position.linear_interpolate( follow ,0.075)

I have continous errors when I run the game → node not found → Platform. This happens when my Player or Enemy collides with the platform.
I have read that somehow this kind of problem appears when you run your game, and MovingPlatform → finds Platform but there might be also other scripts looking for Platform and they can’t find it.

One thing im sure, I don’t have other script or node named Platform.

In this case, how can I resolve the problem without changing my node structure?

I use a tween to move the platform.

Judging from the code you provided you’re using linear_interpolate, not a Tween.

I have continous errors when I run the game → node not found → Platform.

If you get an error, never paraphrase it. Post here exactly as it is!

This happens when my Player or Enemy collides with the platform.

So… What code are you running when that collision happens? (Each error should come with the line of code the error appeared) Without knowing your code this is impossible to fix, but you’re likely trying to get a node using the wrong path or have freed or renamed or moved the node you’re trying to get before getting it.

njamster | 2020-06-18 12:41

Hello njamster,
For statement 1:
This is the rest of the code, that happens before the func _ physics_ process function :
func _ ready ():
_ init _ tween ()

func _ init _ tween ():
var d = move_to.length()/float(300)
tween.interpolate_property(self,“follow”,Vector2.ZERO,move_to, d, Tween.TRANS_LINEAR,Tween.EASE_IN_OUT,2)
tween.interpolate_property(self,“follow”,move_to, Vector2.ZERO, d, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT, d + 2)

P.S tween is of type Tween

For statement 2:
This error appears when the Player sits on the Platform, or the Enemy ( they are type KinematicBody2D), and it is printed every frame of the game:

ERROR: Node not found: Platform.
At: scene/main/node.cpp:1381

For statement 3:
I don’t have any code , I just have a CollisionShape2D created for each of Player, Enemy and Platform also.

Riri | 2020-06-19 08:42


To format your code properly each line has to start with 4 spaces, each additional 4 spaces will equal another indentation layer. Otherwise it’s interpreted as Markdown.


To make sure: If you double-click the error it does not take you to a specific line of your code where the error occurs, it only links to Godot’s source code?


I’m fairly certain the problem does stem from code you’ve written though. If not at this place, then somewhere else. As I’ve written already above, the error tells you that you’re trying to get a non-existent node and that might either be because it really isn’t existing anymore at that point (because you freed it), isn’t existing yet (because you try to access it before the node is added to the tree), isn’t a direct child of the node your script is attached to or the node simply doesn’t have this exact name.

So in order to find the issue, one would need to know:

  1. in which script the error occurs
  2. to which node that script is attached to
  3. how the scene tree looks like when the error occurs

Either provide those informations or upload your example project, so I can take a look.

njamster | 2020-06-20 10:18


Thanks, I didn’t know that

It works.

So the problem was that in the current scene , my parent node couldn’t find node “Platform” in the scene tree, it is implemented in a different scene and after I added it into the big scene, it only shows the parent of that scene, not his children also. I resolved the problem.

Thanks for your patience & helping me!

Riri | 2020-06-21 09:31