How to call a track to play it at the start of an animation?

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

Hello, how to play a music stream at the start of an animation please? Conected my audiostreamplayer with the started animation, added as its script: ‘func _on_AnimationPlayer3_animation_started(change2): play()’ but that doesn’t play the sound…

I know i should use a function to call the track and play it, but what’s the syntax?

:bust_in_silhouette: Reply From: Footurist

In your AnimationPlayer, when you add a track you can chose Function Call Track. When you add a key to this track, you can define in it a function, that will be called on the node, that you specified the track for, arguments can be passed. So you give that track a function that does

AudiostreamPlayer2D.play()

in a key at the start of your animation.

Sry, but how to chose the Function call track when addin the track, and definin in it a function? Or are you just talkin about the settin of keys, and their effects, in animation tracks? Cause I’ve set a playin key at the beginin of my animation, it just don’t play it…

Syl | 2018-03-07 13:25

Upload your project, i’ll show you how.

Footurist | 2018-03-07 13:27

Upload? A screenshot? Look: Imgur: The magic of the Internet
You can see my unefective playin track…

Syl | 2018-03-07 13:57

No, I mean your project packed as a .rar for exampe, so I can have a close look.

Footurist | 2018-03-07 14:12

But how to upload it?

Syl | 2018-03-07 14:38

https://files.fm/

Btw: You should use google a bit more…

Footurist | 2018-03-07 15:03

Ok, rarely uploadin files you know.

Here’s the link: Onyris | Files.fm.

79MB?! As a zip, for 4 light scenes? How come? What’s the weight of a full 3D game??

Syl | 2018-03-07 15:20

The solution is rather simple: You actually never started the animation… You either have to hit the little A at the top right corner of the animation panel or you have to start it via script:

AnimationPlayer.play("the_animation", 0, 1) # anim_name, initial offset, speed

Footurist | 2018-03-07 16:30

Are we talkin of the chaos scene? Cause that’s here that I want the audiostream of the ‘who’ collisionpolygon to start in the animationplayer3.
And the animation start with a play key at the beginin, but without playin the audiostream… With that script in ‘who’:

extends CollisionPolygon2D

func _on_Area2D_input_event( viewport, event, shape_idx ):
if event is InputEventMouseButton:
if event.get_button_index() == BUTTON_LEFT and event.is_pressed():
get_node(“AnimationPlayer3”).play(“change2”)

func _on_AnimationPlayer3_animation_finished( change2 ):
get_tree().change_scene(“res://Scenes/Soul.tscn”)

func _on_AnimationPlayer3_animation_started(change2):
AudioStreamPlayer.play()

Syl | 2018-03-07 19:05