0 votes

when I call the instance method through the player's code, the game crashes,
but if i call the method in the code of the magic_blast instance itself via
_ready () then everything is fine
how to call the method correctly?
here is the player code:

void Player::Fire(){
    if (i->is_action_just_pressed("ui_attack")){
        Node2D* magic_blast = cast_to<Node2D>(MAGIC_BLAST->instance());
        Node2D* pos_node = get_node<Node2D>("Position2D");

        if (Math::sign(pos_node->get_position().x) == 1){   
            magic_blast->call( "SetMagicBlastDirection", Array::make(1));
        }
        else if (Math::sign(pos_node->get_position().x) == -1){
            magic_blast->call( "SetMagicBlastDirection", Array::make(-1));
        } 

        get_parent()->add_child(magic_blast);
        magic_blast->set_position(pos_node->get_global_position());

    }
} 

in the instance, using the method, I change the direction of the fireball, but when I change the direction to -1, the game crashes

in Engine by (29 points)

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.