I have this code that is used to detect which side of a ladder so the player could jump away off it.
func ladder_raycast_detection_for_all_states(): ### (IN PROCESS())
if raycast_body.is_colliding():
### GET WHICH SIDE OF LADDER TO APPLY JUMP OFF
var raycast_body_collider = raycast_body.get_collider()
var raycast_body_collider_normal = raycast_body.get_collision_normal()
if raycast_body_collider.is_in_group("ladder"):
ladder_normal = raycast_body_collider_normal
state = States.LADDER
But occasionally when it collides with object NOT in a group âladderâ it throw this error:
E 0:00:45:163 ladder_raycast_detection_for_all_states: Attempt to call function âis_in_groupâ in base ânull instanceâ on a null instance.
Iâm not sure why it occasionally detects a null instance. Shouldnât this âif raycast_body.is_colliding() + if raycast_body_collider.is_in_group(âladderâ)â only detect an object in a group âladderâ?
get_collider() is returning null for some reason, the grouping shouldnât matter your error is specifically about calling a function on null not that something is or isnât part of a group.
Very odd since the is_colliding() check passes therefor the get_collider() function should return something valid. Do you use await in this function, that could cause errors. Did you edit this sample down before posting it? You could ignore the error by adding another check, but this may only make it harder to find errors with the ladder.
if raycast_body_collider != null and raycast_body_collider.is_in_group("ladder"):
No I donât have await in my script and this is the full code.
func ladder_raycast_detection_for_all_states(): ### (IN PROCESS())
if raycast_body.is_colliding():
### GET WHICH SIDE OF LADDER TO APPLY JUMP OFF
var raycast_body_collider = raycast_body.get_collider()
var raycast_body_collider_normal = raycast_body.get_collision_normal()
if raycast_body_collider.is_in_group("ladder"):
ladder_normal = raycast_body_collider_normal
state = States.LADDER
if is_on_floor():
state = States.FLOOR
if Input.is_action_pressed("up"):
velocity.y += 1
elif !is_on_floor():
state = States.LADDER
I canât reproduce the error consistently so itâs hard to know what is wrong.
Very odd since the is_colliding() check passes therefor the get_collider() function should return something valid
Iâm still curious to find out what could possibly be the cause. I see this error once a full moon for awhile and I just kinda brushed it off until now.
My raycast size is 0.5m and in the latest error instance my player simply walked, with normal walking speed, into a collider cube and the error occurred when raycast was still inside the cube. Any idea?
Oh yes, I actually have 2 different cubes in the same position and the culprit is probably the one that has call_deferred(âqueue_freeâ) on it. Thank you.
(Although I recall error also happens when I hit some other wall or platform too but iâll mark this solved for now. If it happens again somewhere else I will make another thread.)