Topic was automatically imported from the old Question2Answer platform.
Asked By
rodan
Hey i’m having an issue where this code:
onready var raycast_floor = $RaycastFloor
func _physics_process(delta):
on_floor = check_on_floor()
func check_on_floor():
for raycast_floor in raycast_floor.get_children():
if raycast_floor.is_colliding():
return true
return false
is throwing an “Invalid call. Nonexistent function ‘get_children’ in base ‘Nil’”.
I believe Godot isnt detecting the child raycasts apart of the parent node RaycastFloor and I don’t know how to fix it. I could use is_on_floor() in place of the raycasts, but later on I plan on implementing wall jumping and since is_on_wall() doesnt work for what I have in mind, I’m stuck with this issue
for raycast_floor in raycast_floor.get_children():
The error means raycast_floor is null. Usually it means $RaycastFloor is probably not the correct path due to a typo.
But also, looking closer… the fact you repeated twice the same variable name is very suspicious. I wonder if it should be warned by the script editor.
Try using a different name for the iteration variable, like this:
for child_raycast in raycast_floor.get_children():
if child_raycast .is_colliding():
return true
@Zylann - Looks like I’ve done it again. Started to answer an unanswered question, gotten sidetracked, and then came back a few minutes later to finish my answer - only then to find it’s already been taken care of.
Didn’t mean to provide a nearly duplicate answer a few minutes later…
jgodfrey | 2020-03-06 14:46
yup changing the variable to child_raycast fixed it, I didnt see what I had done haha. I have another issue now, the Raycasts aren’t colliding with the TileMap despite sharing the same collision mask but i’ll give it a go and see what i come up with. Thanks for your help!