0 votes
  onready var raycast = get_node("RayCast2D")

func _physics_process(delta):
    var playerposition = get_parent().get_node("Player").position
    var coll = raycast.get_collider()
    if coll.is_in_group("player"):
        print("TIS BUT A SCRATCH")

The code is above. I'm getting the error "Attempt to call function 'is _in _ group' in base 'null instance' on a null instance" Does anyone know why this could be happening?

in Engine by (18 points)

1 Answer

+1 vote

As per the official documentation, get_collider() might return null in case of no collision:

    Object get_collider ( ) const

Returns the first object that the ray intersects, or null if no object is intersecting the ray (i.e. is_colliding returns false).

You need to check why the collision is not happening first.

by (846 points)

Nice, thanks, I added in an if raycast.is_colliding(): and that solved the crashes, Thanks for your help!

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.