This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
–1 vote

I'm currently following this tutorial 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_state(delta, sprite)

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

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

 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!)

Godot version godot 3.3
in Engine by (58 points)

1 Answer

0 votes

I think you have to load the ghost first:

func roll_state(delta, sprite):
      self.sprite = sprite
      velocity = velocity.move_toward(roll_vector * ROLL_SPEED, ACCELERATION * delta)"Roll")
by (80 points)

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

I think the problem is, that you didnĀ“t set the variable "sprite"

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.