I've been getting a really annoying error message and I know the problem is referencing the object, but I can't seem to fix it

Godot Version

4.3

this is going to be a list of global variables but i can’t seem to get it to work

Seems like it can’t find a child node named “RigidBody2D” in your scene.

Maybe you’ve renamed it to something else and the reference needs updating? Or it’s not a child of the current node in which case the node path needs changing.

3 Likes

No, still get the error.

Could you post a screenshot of your scene’s nodes?

I guess you want to make the position of an object global so that it can be used by other objects. For this, I’ll use this method:
Create a script named Global.gd
Add it to Autoload with the name Global
In Global.gd:

var object_position: Vector2

In object script:

func _process(delta):
  Global.object_position = $RigidBody.position

In other objects:

var object_position: Vector2
func _process(delta):
  object_position = Global.object_position

Sure, here.
Untitled Project-00;10;30;00
(the first Node2D is the one with the script in it)

in this screenshot there is no script attached to the first Node2D though (i think you have attached it to the last Node2D by mistake)

1 Like

The node2d does not a rigidbody, I think this is why you have error. You are calling a rigidbody2d function, from a node2d.

If the script is on the Rigidbody2d, it should work I think. Not if the script is on the ‘Node2D’.

Maybe you are trying to call the position function/variable on the other Node that is the scene, the rigidbody2d node? You need reference to that node first.

But yeah, Node2D has not the ‘Rigidbody2d’ class.

Just to clarify that the issue isn’t calling a RigidBody2D function from the wrong place, but likely a reference issue as you mention in your third paragraph.

$RigidBody2D is shorthand for get_node("RigidBody2D"). Node2D also has a position property - in fact, that’s where Rigidbody2D inherits it’s position property from.

I think @syntaxerror247 may be right in noticing the script could be attached to a different Node2D node. Either the script needs moving, or the get_node() expression needs updating with the appropriate relative path.

3 Likes

Im sorry, this is an old photo, the first Node2D is the one with the variables.