This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So, I keep getting this message saying "Attempt to call function 'get_collider' in base 'null instance' on a null instance. I have no clue how to fix it. I followed a tutorial saying that I needed to enter in this code, I have no idea why it didn't work because it worked for the person making the tutorial, but here is the code that's giving me a problem:

        if $Raycast2D2.get_collider("/root/Proto/Player"):
        var player = get_parent().get_parent().get_node("/root/Proto/Player")
Godot version 3.3
in Engine by (39 points)

Well first off get_collider() doesn't take a parameter so that code is just wrong.

It is failing because at the time you are calling the get_collider() function (if it even works with being called with "/root/Proto/Player" as the parameter) the engine can't find a child node of the node that this script is attached to named Raycast2D2 so $Raycast2D2 returns null and null is just a fancy way of saying nothing. null has no function named get_collider() so it crashes.

That is absolutely awful code so I highly recommend following another tutorial. Check out the Youtube channels: GDQuest, KidsCanCode, Heartbeast, or Game Endeavor to learn how to properly create games in Godot.

Try looking in the Godot API for the function calls (such as get_collider()) used in the code.

It looks as though one of the references the above code is using, $Raycast2D2, is null, meaning it isn't pointing to a node.

Oh Wow, I have no clue how it worked for the guy in the tutorial then, anyways thank you for answering and suggesting better tutorials.

Ah ok, thank you for answering

Please log in or register to answer this question.

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.