Sprite node is null

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

I’m currently following this tutorial https://www.youtube.com/watch?v=fp_XugQvOKU&t=578s and change it a little bit (to fit with my project) and get this error:

Invalid get index 'texture' (on base: 'Nil').

the problem maybe because of my Sprite is null, but I don’t know how to fix it, here is my code:

var sprite
var ghost_scene = preload("res://ghosteffect.tscn")

func _process(delta):
 match state:		
	ROLL:
		roll_state(delta, sprite)

func roll_state(delta, sprite):
 self.sprite = sprite
 velocity = velocity.move_toward(roll_vector * ROLL_SPEED, ACCELERATION * delta)
 animationState.travel("Roll")
 move()
 instance_ghost()

func instance_ghost():
 var ghost: Sprite = ghost_scene.instance()
 get_parent().get_parent().add_child(ghost)

 ghost.global_position = global_position
 ghost.texture = sprite.texture
 ghost.vframes = sprite.vframes
 ghost.hframes = sprite.hframes
 ghost.frame = sprite.frame
 ghost.flip_h = sprite.flip_h

I have omitted some codes which aren’t related to the sprite node, so please ask if you guys need more information (million thanks for the help!)

:bust_in_silhouette: Reply From: TTF DPC

I think you have to load the ghost first:

func roll_state(delta, sprite):
      instance_ghost()
      self.sprite = sprite
      velocity = velocity.move_toward(roll_vector * ROLL_SPEED, ACCELERATION * delta)
      animationState.travel("Roll")
      move()
     

hmm do not really change any things but still thanks for lending a hand :slight_smile:

cookieoil | 2021-09-06 07:34

I think the problem is, that you didn´t set the variable “sprite”

TTF DPC | 2021-09-06 15:32