How to change the music when enemy sees the player

RaeJjin0

Member
Sorry to bother you, but i am trying without success to setup my behavior tree, to make it store the actual song playing (save the time played), change the audio for a battle song for example, and then when the ennemy dies fade out the battle song and switch it for the stored first song... How could i achieve this ?
 
There are a lot of different ways that you can do this so it really depends on how your game/tree is setup. What does your behavior tree look like? At a high level you could use an event system to send an event when the enemy dies and then do the transition.
 
It's the tree of Agent Nolan from the BD third person melee demo scene, I am not very used of trees, this is why I am struggling to setup this audio changer ?
 
Personally I wouldn't add the background music to the behavior tree at all since that isn't directly related to the AI for the agent. You could instead subscribe to one of the death events and play the music in a separate, new component.

 
That is a good idea sir, but even if know I have an idea on how to change the music when the enemy dies, how can I start the music when the enemy detect the player, without behavior tree? And to store the background music before playing the battle song, so that the background music replays at the right timer when the enemy dies? This is the hardest point in my opinion x)
 
You can use the event system to handle all of those situations. When the enemy sees a player you can send an event from the behavior tree which the a music component is listening to and from there change what music is played.
 
Thank you so much for your clarification Justin, I understand the point theorically, but is there any tutorial showing us how to do so visually or with screenshots ? If there isn't and you cannot do so it will be ok, I will do some more research
 
There isn't a specific tutorial on this but you can use the Execute Event task to then have your new component receive the event. Take a look at this page for how the event system works:

 
For thoses wondering in the future, I managed to do it thanks to the "Tasks" tab in Behavior Designer. I searched in the Tasks search bar for "Audio" and "Game", and found a bunch of amazing tasks. I decided to create two empty objets containing audio sources of respectively Music1 and Music2, disabled those gameobjects, then played with "Set Active" task of BD in the GameObjects tab. For music1, instead of disabling the gameobject, i simply used the Pause task into AudioSource tab, and used the OnDeath event into the character health component of the enemy to disable the music2 and unpause the music1.
 
Top