Can't play sprite animation(read description)

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

Imgur
Attempt to call function ‘play’ in base ‘null instance’ on a null instance.
I’m trying to play animation when my player dashes but im unable to do so. Godot gives me this error when I try to play one animation from my animated sprite of my character. When I used similar code for a different animation it worked but it isn’t working here. Any help would be appreciated.

Screenshot

Dlean Jeans | 2019-07-02 07:45

Can you please help me solve this problem?

Nanogines | 2019-07-02 12:17

Seems like your Sprite disappears or something.
Have you check Remote when you run?
And why the Pixel variable?

Dlean Jeans | 2019-07-02 12:50

Remote :
https://imgur.com/IPjSvX8

Nanogines | 2019-07-02 14:30

All of Pixel’s children nodes are gone! Did you spawn or add it properly?

Dlean Jeans | 2019-07-02 17:44

Ok I’ll get to the root.

I wanted to create a simple dash effect for my game. I had made a timer previously for the character death. I needed to use a timer for the dash so I named it Timer2. But when I used in code the $Timer worked for the upper but $Timer2 didn’t work as it had null instance problem. So I created the timer in code. But I don’t know the animated sprite is linked with it. Another question, can we have two timers in the same scene?How?
Preview of the game : https://www.youtube.com/watch?v=mjTMbYgx-u8

Nanogines | 2019-07-04 06:30

Yes, it’s totally possible to have any number of Timer in the same scene.
You can name the first one DeathTimer and the second DashTimer.

If that doesn’t work then post your dashing code here. That seems to be where the root cause lies.

Dlean Jeans | 2019-07-04 08:20

My player code(I think you saw this) :

extends KinematicBody2D

const UP = Vector2(0,-1)
var motion = Vector2()
var is_dead = false
var grav = 18
var timer = null
var is_dashing = false

func _physics_process(delta):
    if is_dashing == true:
        motion.y += grav
        motion.x += 1000
    if is_dead == false:
        motion.y += grav

        motion.x = 300
        if Input.is_action_pressed("ui_right"):
            dash()
        if is_on_floor():
            if Input.is_action_just_pressed("ui_select"):
                motion.y = -400
                if Pixel.has_node("pass_through"):
                    Pixel.set_collision_mask_bit(1,false)
                else:
                    motion.y = -400
        move_and_slide(motion,UP)

        if get_slide_count():
            for i in range(get_slide_count()):
                if "Fire" in get_slide_collision(i).collider.name:
                    dead()
        if get_slide_count():
            for i in range(get_slide_count()):
                if "Flame" in get_slide_collision(i).collider.name:
                    dead()


func dead():
    is_dead = true
    $DeathSound.play()
    motion = Vector2(0,0)
    $Particles2D.emitting = true
    $Sprite.play("dead")
    $CollisionShape2D.disabled = true
    $deadtimer.start()

func _on_Luck_Bits_body_entered(body):
    global.luckscore +=1
    print(global.luckscore)

func _on_Spring_body_entered(body):
    motion.y = -500

func _on_deadtimer_timeout():
    get_tree().reload_current_scene()

func _on_dashtimer_timeout():
    motion.x = 300

func dash():
    is_dashing = true
    motion.x = 5000
    $dashtimer.start()

Nanogines | 2019-07-04 11:08

What is Pixel in this line Pixel.has_node("pass_through")?

Dlean Jeans | 2019-07-04 12:06

It is just another functionality I added to my character to make it pass through a platform. Pass through is layer. I don’t think it is much related to this.

Nanogines | 2019-07-06 04:45

I mean Pixel. I see no Pixel declared in this script. Is it a singleton or autoloaded?

Dlean Jeans | 2019-07-06 04:59

Yes, it is singleton.

Nanogines | 2019-07-06 05:35

:bust_in_silhouette: Reply From: Dlean Jeans

Remove the Pixel singleton from AutoLoad, you don’t need it.
Also remove Pixel. from the script.