invalid set index 'rotation_degrees' (on base: 'null instance') with value of type 'float'

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By szccornish

Hi guys, im new with coding… i have been wondering why it’s not working, my rotator cursor doesn’t move and it keep crashing after 2 second. and it always gave me the " invalid set index ‘rotation_degrees’ (on base: ‘null instance’) with value of type ‘float’ "

any feedback will be really appreciate

below is my code

extends KinematicBody2D

const MAXSPEED = 80
const ACCELERATION = 500
const FRICTION = 500

var velocity = Vector2.ZERO

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get(“parameters/playback”)

onready var pointer := $Pointer
onready var ray:= $Pointer/RayCast2D

func _physics_process(delta):

var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()#diagonal have same speed with linear speed

if input_vector != Vector2.ZERO:
	animationTree.set("parameters/Idle/blend_position", input_vector)
	animationTree.set("parameters/Walk/blend_position", input_vector)"Walk")
	velocity = velocity.move_toward(input_vector * MAXSPEED, ACCELERATION * delta)
elif velocity  != Vector2.ZERO:
	velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
move_and_slide (velocity)

func rotate_pointer(pointer_direction: Vector2)-> void:
var temp = rad2deg(atan2(pointer_direction.y, pointer_direction.x))
pointer.rotation_degrees = temp

How does your scene-tree look like? Does the KinematicBody2D this script is attached to have a direct child called “Pointer” (case-sensititive!)? This error is basically telling you that you’re trying to set a property on a null-object, i.e. the object does not exist.

njamster | 2020-04-24 19:34

oh gosh i have to rename Node2D to Pointer for it to work, thank you so much it was really helpfull

szccornish | 2020-04-24 22:01