Help with varible

Question

My sprite value, or " my_own_effing_sprite" value is null for some reason

Idk why, I selected it to be one of my sprites, and I checked it by printing the value, and sometimes its what I want, and Null other times.

extends CharacterBody2D

@onready var pickle_cyborg: Sprite2D = $PickleCyborg

@export var my_own_effing_sprite : Node2D
@export var SPEED = 150
const JUMP_VELOCITY = -400.0
@export var MAX_HEALTH = 100
var HEALTH = 0
@export var GroundCheck : Node2D
@export var direction = 1
@export var flying = false
@export var Is_Boss = false
@export var jump_force = 2
@export var edge_check = true
var target : String = "ggg"
@export var BULLET = preload("res://scenes/touchibles/PowerUps/Fire it up.tscn")
var frozen = false


#TO DO!! !!!!!

#1.    Figure out why and fix the sfhsruigfvb ocationaly resulting in a null value



func _ready() -> void:
	pickle_cyborg.position.x = 11
	HEALTH = MAX_HEALTH

func _physics_process(delta: float) -> void:
	$PickleCyborg.flip_h = false
	if is_on_wall():
		direction = direction * -1
	if flying == false:
		if not GroundCheck.is_colliding():
			if edge_check == true:
				direction = direction * -1
	if flying == false:
		velocity += (get_gravity() * delta / 3)
	velocity.x = SPEED * direction
	GroundCheck.position.x = 10 * direction
	if HEALTH < 1:
		queue_free()
		if Is_Boss == true:
			var BULLET2 = preload("res://scenes/scripts/Touchibles/PowerUps/DucKEY.tscn")
			var CUBEYS2 = BULLET2.instantiate()
			CUBEYS2.position.x = position.x
			CUBEYS2.position.y = position.y - 10
			get_tree().current_scene.add_child(CUBEYS2)
		if not Is_Boss == true:
			var CUBEYS = BULLET.instantiate()
			CUBEYS.position.x = position.x
			CUBEYS.position.y = position.y - 10
			get_tree().current_scene.add_child(CUBEYS)
	



	move_and_slide()


func Jump():
	pass




func _on_damage_2_body_entered(_body: Node2D) -> void:
	pass


func _on_area_2d_body_entered(body: Node2D) -> void:
	if Is_Boss == true:
		if (body.scene_file_path == "res://scenes/character_body_2dd.tscn"):
			pass
1 Like

Tough to say, are these objects instantiated often during the game? did you assign the exported variable for each object?

Put print(get_path()) into _ready().
Any errors in the debugger btw?

Well there you have it. Node paths you assign to @onready vars are incorrect.

1 Like


thats weird, first it identifies as the sprite, then null

1 Like


Why? How? my varible is set to be the sprite

Oh wait, another enemy, (the bullet) was not connected to a sprite, and I did not know. THX