Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | F0remNKB |
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