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

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.


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 :

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 :

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"):
        if is_on_floor():
            if Input.is_action_just_pressed("ui_select"):
                motion.y = -400
                if Pixel.has_node("pass_through"):
                    motion.y = -400

        if get_slide_count():
            for i in range(get_slide_count()):
                if "Fire" in get_slide_collision(i)
        if get_slide_count():
            for i in range(get_slide_count()):
                if "Flame" in get_slide_collision(i)

func dead():
    is_dead = true
    motion = Vector2(0,0)
    $Particles2D.emitting = true
    $CollisionShape2D.disabled = true

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

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

func _on_deadtimer_timeout():

func _on_dashtimer_timeout():
    motion.x = 300

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

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.