![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Idleman |
It usually works, but not sure why the following code is not working. I could not access the function in an instanced scene.
func show_spirit_flame():
var flame = load("res://Object/FloatingFlame.tscn").instance()
flame.position = Vector2(195, 500)
flame.set_flame()
call_deferred("add_child", flame)
The problem is the flame.set_flame( ), the bug says :
Invalid call. Nonexistent function”play” in base “Nil”
The function is simply an AnimationPlayer.play(“Flame”), and it works fine in the flame scene. Have no ideas why it could not be accessed from the main scene. If any one knows what the problem might be, it would be very helpful, thank you.
Because it is not scene yet. I suppose AnimationPlayer won’t do anything until ready() is called. Most likely You just have add_child of your flame to the scene_tree and then call set flame.
Inces | 2021-12-19 06:51
Thanks for replying, that seems to be the case. I use add_child instead of call_deferred and put the set_flame() after add_child, and it works.
Idleman | 2021-12-19 10:28