Tag

unity

Footsteps

By | Uncategorized | No Comments

Now we have our ambience, and hopefully a few spot sounds around the scene. If using the FPSController, Unity’s default footstep sounds are applied, but they are repetitive and we will always want to use our own samples, changing them according to the surface our character is on. This involves a lot of prep work in Wwise and Unity, but it is a very important part of building a game. There are a number of ways to implement footsteps. If using the FPSController in Unity, we can replace their footstep sound with ours in the FPSController script. If your game has character animation, we can call our footstep event during the animation sequence, when the characters foot touches the grand.

  1. Go to the ‘Game Syncs’ tab in Wwise. Right-click the Default Work Unit under the Switches heading, and create a new Switch group called Footsteps. Now, right-click the Footsteps Switch group, and create two new switches – Grass and Concrete (or whatever footstep sounds you are using). More info on working with Switches here.
  2. Now, we need to set up our Footsteps event in Wwise. Go to the Actor-Mixer hierarchy, and right-click on the Default Work Unit. Create a new Switch container, also Footsteps. In the property editor here, we can see the ‘Group’ and ‘Default’ options. We can select our ‘Footsteps’ Switch group here, and choose which surface we want to be our default footstep sound.
  3. Right-click on the Footsteps Switch container, and add two random containers as children. These will contain our footsteps. Add grass footsteps to one random container, and concrete to the other.
  4. With the Footsteps Switch container selected, we can see under the property editor there is a tab for ‘assigned objects’, with our Switches. Drag and drop the Grass Random container to the Grass Switch, and the Concrete Random container to the Concrete switch.
  5. Once this is done, right-click the ‘Footsteps’ Switch Container and create a Play event, adding it to the SoundBank like any other. We can test to see if our Switch container is working by changing the Switch in the transport control.
  6. Now, move over to Unity. Presuming we have downloaded the ‘Characters’ assets package, and are using the FPSController, we will need to move the FirstPersonController script into our Audio_Scripts folder. This is purely hierarchical, as Wwise only looks in top level folders. The FirstPersonController script can be found here, simply drag the script into our Audio_Scripts folder.
  7. Open the FirstPersonController script (it will look quite daunting). Navigate to line 159 of the code, which should look like this.
    PlayFootStepAudio();
    
  8. Highlight this line of code, replace it with
    AkSoundEngine.PostEvent("Play_Footsteps", gameObject);
    

    and save the script.

  9. Enter Play Mode in Unity, and now as we move around we should hear our Default footsteps! Now, how do we switch to our second set of footsteps?
  10. Create a new empty GameObject, and add a Box Collider that is a Trigger.
  11. Create a new C# script in our Audio_Scripts folder, name it Footsteps_Switch. Copy the following code in.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Footsteps_Switch : MonoBehaviour {

    public string switchGroup;
    public string switchEnter;
    public string switchExit;
    public GameObject location;

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            AkSoundEngine.SetSwitch(switchGroup, switchEnter, location);
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            AkSoundEngine.SetSwitch(switchGroup, switchExit, location);
        }
    }
}
//https://audioprogblog.com/

Now drag the Footsteps_Switch script onto the GameObject, and in the inspector we will see fields for the Switch Group, the switch we want to use when we enter the collider, and the switch we want to use when we exit the collider, as they are named in Wwise. Enter the names into these fields, and use the FPSController as the location GameObject.

Enter Play mode again. Presuming everything is working correctly, you should be moving into and out of the collider and hearing the footsteps change. But there is one more issue here – try jumping! We will hear that the footsteps continue playing even if our character is in the air. Thankfully, in the FirstPersonController script, there already exists a variable that tells us when the player is grounded.

Open the FirstPersonController script, and navigate back to line 159, where we previously entered our Wwise Event. We will add an If Statement that will only play the Wwise Event IF the character is grounded.

if(m_CharacterController.isGrounded)
{
AkSoundEngine.PostEvent("Play_Footsteps", gameObject);
}

Troubleshooting

Error posting Wwise Event – make sure you have dragged the FPSController script into the Audio_Scripts folder, and that the Audio_Scripts folder is a top level folder, directly under the assets folder.

Ensure that the Switch Group, and Switch Enter/Exit fields are spelled correctly (case sensitive)

Event not triggering but no error – Ensure the FPSController or equivalent is set to the location. Ensure the FPSController is tagged as “Player”.

Compile error in FirstPersonController script – It’s possible that through making changes to the code, you may forget a semicolon, remove a curly bracket or forget parentheses. Read through the examples and make sure you remove, copy and paste the code exactly as it is formatted here.

#wwise #unity #footsteps #firstpersoncontroller #FPSController #jump #switch

Triggers

By | Uncategorized | No Comments

Our first sound is in! As it is a 2D ambience, the sound plays in the background from when we enter play mode. What about sounds that are triggered as we move around?

  1. First, create a new GameObject in the Unity hierarchy by right-clicking in the hierarchy and pressing ‘create empty’. Call it whatever you like, I’ll go for ‘Door’.
  2. In the inspector, hit ‘add component’ and add a box collider using the search field. Once we have added the box collider, tick the ‘Is Trigger’ checkbox. This collider can now be used to trigger events.
  3. Next, we need to Tag the FPSController object, or your own equivalent. Select the FPSController GameObject in the hierarchy, and at the top of the inspector select the ‘Tag’ drop-down menu. Tag the FPSController as ‘Player’. This is very important, as we will shortly see.
  4. Go to our Audio_Scripts folder, and create a new C# script called Trigger_Enter. Copy the following code.
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Trigger_Enter : MonoBehaviour
    {
        //wwise event
        public string wwiseEvent;
        //GameObject emitting sound
        public GameObject location;
    
        //Wwise Event will be called when a GameObject with the "Player" tag
        //enters the collider of the GameObject this component is attached to
        private void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag == "Player")
            {
                AkSoundEngine.PostEvent(wwiseEvent, location);
            }
        }
    }
    //https://audioprogblog.com/
    
  5. This code is telling Unity to call the Wwise Event only when a collision happens with the GameObject, and only if the colliding GameObject has the “Player” tag. Without the “Player” tag, any colliding object would call our Wwise event! With the Player tag, the sound will only be triggered when the player collides with the GameObject. Add the Trigger_Enter script as a component to the ‘Door’ GameObject (drag and drop, or select Add Component in the inspector).
    Note that I have used the same variable names for this example, ‘wwiseEvent’ and ‘location’, as the last example. This is generally bad practise, particularly once you begin writing scripts and classes that reference each other within the game. Each variable should have a unique name to avoid confusion down the line, but this will do for these standalone examples.
  6. Now, we must create a new Wwise event. Use the same process as before, adding a sound into Wwise and creating a Play event. Add the event to the SoundBank, save the Wwise session and Generate SoundBanks.
  7. Go back to the ‘Door’ GameObject in Unity, and in the Hierarchy we will see the Trigger_Enter script with the wwiseEvent and location fields. Add the Wwise Event name, and as the location add the ‘Door’ GameObject, or your equivalent. This means that the sound will emit from the ‘Door’ GameObject in Unity.
  8. Enter play mode in Unity, and move to where the GameObject is positioned. We should hear the event is triggered when we reach the collider.
  9. Try copying this script into a new C# script titled Trigger_Exit, and replacing ‘OnTriggerEnter’ with ‘OnTriggerExit’. Note that the sound will now be triggered when the FPSController leaves the collider, not when it enters.

    TroubleshootingWwise Event ID Not Found – Similar to the previous post, SoundBanks have not been generated in Wwise, or have not been loaded in Unity. The event name in Wwise may not match the event name in the wwiseEvent field in the inspector in Unity.

    Box Collider not triggering sound – ensure the ‘Is Trigger’ checkbox is selected in the inspector in Unity, where we added the Box Collider component. If it is not a trigger, it will not act as a trigger during collisions.

    #wwise #unity #trigger #collider #ontriggerenter

Our First Sound

By | Uncategorized | No Comments

Finally, we are ready to play back our first sound in Unity!

    1. Create another new empty GameObject in Unity, by right clicking in the Hierarchy and selecting Create Empty.
    2. In the Unity Project window, under the Assets folder, create a new top level folder called Audio_Scripts. This will contain all C# scripts related to audio.
    3. Right click in the Audio_Scripts folder, and create a new C# script called Play_Start. Insert the following code and save the script.
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      
      public class Play_Start : MonoBehaviour {
      
          //public string for Wwise Event name
          public string wwiseEvent;
          //public GameObject defines the GameObject this component is attached to
          public GameObject location;
      
          //everything in void Start happens upon starting the game
          void Start ()
          {
              //calls the wwise event
              AkSoundEngine.PostEvent(wwiseEvent, location);
          }
      }
      //https://audioprogblog.com/
      
    4. Now we can place the script on a GameObject in the hierarchy. Create an empty GameObject in the hierarchy called ‘Audio’, and drag the Play_Start script into the inspector. We will see the script appear as a component, and we will see that our public wwiseEvent and location variables are accessible directly in the inspector. Enter the name of the Wwise Event in the wwiseEvent field (In my case this is ‘Play_Ambience’). Drag the GameObject we want the sound to emit from into the location field. As this is a 2D sound, I use the FPSController.
    5. Enter play mode! If the sessions have been set up correctly and the event name in the inspector matches your Wwise event name, our sound should play back as soon as the game starts.

Troubleshooting

Some common errors that are thrown around this time include:

Wwise Event ID Not Found – Ensure the Wwise session has been saved, the SoundBanks have been generated in Wwise and the AkBank component is on a GameObject and being loaded on start. Also make sure the spelling of the Wwise Event and the wwiseEvent field in the inspector in Unity are the same (everything in code is case sensitive). The Wwise Picker tab in Unity also has an option to refresh the project and generate SoundBanks.

#wwise #unity #csharp #inspector

Wwise & Unity Project Set Up

By | Uncategorized | No Comments

Once the Wwise and Unity projects have been integrated, we are ready to set up our Wwise session.

  1. Open the Wwise project associated with the Unity project.
  2. Look at the Project Explorer window. Create a simple Sound SFX by right clicking on the Default Work Unit in the Actor-Mixer Hierarchy in the Wwise Project Explorer (more on these terms here). Select ‘New Child’, and ‘Sound SFX’.
  3. The new Sound SFX will appear in red, meaning there is no audio attached to it. Right click the Sound SFX and select ‘Import Audio Files’, or simply drag an audio file onto the Sound SFX object from your file explorer. Rename the Sound SFX, I went for Ambience here.
  4. Check the sound file has been attached to the Sound SFX object by playing it back in the Wwise Transport Control, or by selecting the Sound SFX and pressing the spacebar. It should play back immediately.
  5. Once we have heard the sound file playing back, we are ready to create an Event. Events have actions associated with them such as Play, Stop etc. This is how the sound is triggered from Unity.
  6. Right click the Sound SFX, select New Event, and Play. This will create an event called Play_Ambience, under Wwise’s naming convention. We should now see the event in the Events tab in the project explorer.
  7. Now we must create a SoundBank. Select the SoundBanks tab in the Project Explorer, right click on the Default Work Unit, select New Child, and choose SoundBank.
  8. Select the Layout tab from toolbar at the top of the screen, and choose SoundBank. We should now see the Default Work Unit, and the SoundBank within it. Go back to the Events tab in the Project Explorer, and drag the Event onto the SoundBank.
  9. Finally, ensure that the SoundBank has been selected, along with the correct platform and language. Save your Wwise project and hit Generate Selected to generate your SoundBank. A confirmation message will pop up confirming when this has been completed.
  10. Now, open Unity and navigate to the Wwise Picker, and expand the Wwise Project. Expand the Events and SoundBanks folders, and under the Default Work Unit headings we should see the Event and SoundBank that we created. This shows that the SoundBank generation has been successful.
  11. One more step! Right click anywhere in the Hierarchy in Unity, and select Create Empty. This will create an empty GameObject, which I have renamed to SoundBank.

    Now drag the SoundBank from the Wwise Picker tab, onto the SoundBank GameObject. We will see a new component appear in the inspector, AkBank. This will load our SoundBank when we launch the game in Unity. Ensure the bank is set to load on start, and that the correct SoundBank is selected under ‘Bank Name’.

    Now our sessions are integrated, and ready to go.

#wwise #unity #soundbanks #events #integration

Wwise & Unity Project Integration

By | Uncategorized | No Comments

This post will be a simple introduction to setting up Wwise and Unity projects. If starting completely new projects, make sure that you have downloaded the latest versions of both Wwise and Unity. If you have an older version of Unity, check its compatibility with Wwise here.

  1. Launch Unity and create a new project. Save the project once it has been created. If  integrating into an existing project, back it up and ensure there are no compiler errors.
  2. Open the Wwise Launcher, and select the Unity tab. The Unity project should show up here.
  3. Select ‘Integrate Wwise into Project’.
  4. Recommended settings are generally OK here. Make sure to choose preferred deployment platforms (Mac, Windows, Android etc).
  5. If you have already created a Wwise project, you can browse for the project path and link it. If you leave the Wwise project path blank, it will create a new Wwise project for you.
  6. Choose integrate, and let it work for a couple of minutes. Once this is complete, the Wwise project will be integrated into the Unity project.
  7. Open the Unity project, and there should now be a Wwise Picker tab in Unity. This window is also available through Window > Wwise Picker in the Unity toolbar.  There will also be a WwiseGlobal GameObject in the Hierarchy. If you can see this, the integration has been successful!

    Note: Wwise will automatically disable Unity’s audio engine during the installation process. Any sounds already in your project using Unity’s audio engine will be disabled.

#wwise #unity #project #integration