0 votes

So I have a Raycast that when it detects the player, it emits a signal called "crossed_line" (for a racing game). I followed the directions of many tutorials to create the following code:
in the Raycast script:

signal crossed_line

func _on_Area_body_entered(body: Node) -> void:
emit_signal("crossed_line")
print ("nice")

func _on_WallDetector_crossed_line():
print ("AH")}

and in the Player script

func _ready() -> void:
var wall = get_node("/Main/Path2D/follow/WallDetector")
wall.connect("crossed_line", self, "handle_crossed_line") 

func handle_crossed_line() -> void:
print ("I crossed the line!")

This is exactly the format I see multiple tutorials have you do, however I get an error in the player script that says "Attempt to call function 'connect' in base "null instance" on a null instance."

When I delete the player script and run the game, the game does print "nice" and "AH" whenever the player crosses the line, so I know that the raycast2d works and that the signal works.

I am also positive that the path to the node is correct.

I am not sure what I could be doing wrong, though I know it's something...any help would be greatly appreciated!

in Engine by (18 points)

1 Answer

0 votes

I get an error [...] that says "Attempt to call function 'connect' in base "null instance" on a null instance."

This error tells you that wall is a null-instance, which is a fancy way of saying it's not defined. Thus it obviously doesn't come with a connect-method you could call!

I am also positive that the path to the node is correct.

I'm not! Wrong paths are the number one reason for this error! Unfortunately, you didn't provide us with the structure of your scene tree, so I cannot really tell. But in case you are right and the nodepath really is correct, then the node does not exist yet when the _ready-function of the player-node is executed.

by (10,469 points)
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 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 webmaster@godotengine.org with your username.