Playing different footstep noises depending on surfaces. (2D)

Hi there, I’ve been trying to get FMOD to play different sound clips depending on the character’s surface they are standing on. Right now, I’ve decided to use a Scriptable Object (SO) to handle this.

In theory, the collider that contains a tag that displays which material the player is standing on has a SO that contains this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMOD.Studio;
using FMODUnity;

[CreateAssetMenu(fileName = “Surfaces”, menuName = “ScriptableObjects/SurfaceScriptableObject”, order = 1)]
public class SurfaceScriptables : ScriptableObject
{
EventInstance playerWalkingOnConcreteFlat;
EventInstance playerWalkingOnWoodFlat;

void Start()
{
    playerWalkingOnConcreteFlat = AudioManager.instance.CreateEventInstance(FModEvents.instance.PlayerWalkingOnConcreteFlat);
    playerWalkingOnWoodFlat = AudioManager.instance.CreateEventInstance(FModEvents.instance.PlayerWalkingOnWoodFlat);


}


void OnTriggerStay2D(Collider2D col)
{

    if (col.tag == "Player")
    {
        {
            aSoundInstance = RuntimeManager.CreateInstance(aSound);
            aSoundInstance.start();
        }
    }

}

        void OnTriggerExit2D(Collider2D col)
    {
        aSoundInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);

    }

}

(Doesn’t compile yet)

And this code is supposed to take whatever audio file is inserted into the SO and insert it into the code block, then play the code to loop his walking sound, before terminating after he leaves the material OR stops moving.

So far I have no idea how to execute this. It should be pretty simple in theory.

  1. SO checks when the player collides with it.
  2. Each SO for the corresponding material has an audio file containing the walk and run sounds.
  3. When it detects a collision and the player moving faster than 0.1 speed, it should play the footstep sound, and stop when the player moves slower than 0.1, OR leaves the collider.

Hi,

What version of FMOD and Unity are you using?

Just to confirm:

  1. AudioManager and FModEvents are singletons that you have created?
  2. You are creating the EventInstances playerWalkingOnXX then in the OnTriggers you are using aSoundInstance.
  3. If you substitute aSoundInstance for one of the others you are creating does this allow you to hear sounds?
void OnTriggerStay2D(Collider2D col)
{
	if (col.tag == "Player")
	{
		{
			playerWalkingOnConcreteFlat.start();
		}
	}
}
void OnTriggerExit2D(Collider2D col)
{
	playerWalkingOnConcreteFlat.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
}

Most FMOD functions return an FMOD Engine | Core API Reference - FMOD_RESULT. I would suggest adding these to your FMOD calls and logging the result if they do not resolve FMOD_OK. This will hopefully provide more information where the function may be failing.

FMOD.RESULT result = playerWalkingOnConcreteFlat.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
if (result != FMOD.RESULT.OK)
{
	Debug.Log(result);
}

Hope this helps!

  1. I am using version 2021.3.16 and fmod version 2.02.15.
  2. Yes.
  3. Not sure I follow.

Here is an updated version including usage of a Scriptable Object (SO) to store any Eventinstances related to Fmod events:

Compiles fine!

FootstepSounds script: using System.Collections;using System.Collections.Generic;using UnityEngine; - Pastebin.com

SO script: using System.Collections;using System.Collections.Generic;using UnityEngine; - Pastebin.com

1 Like

Hi,

That is good to hear!

Another test you could do is checking the created event instance isValid(), FMOD Engine | Studio API Reference - EventInstance::isValid().

FootstepScriptables.playerWalkingOnConcreteFlat = AudioManager.instance.CreateEventInstance(FModEvents.instance.PlayerWalkingOnConcreteFlat);

if (!FootstepScriptables.playerWalkingOnConcreteFlat.isValid())
{
    // Log error here
}

What are the current issues you are running into now that it is compiling?