# Different terrains script UNITY. Parameter doesn't change

**URL:** <https://qa.fmod.com/t/different-terrains-script-unity-parameter-doesnt-change/16378>\
**Category:** Unity\
**Created:** [October 29, 2020, 8:21pm UTC](https://qa.fmod.com/t/different-terrains-script-unity-parameter-doesnt-change/16378 "2020-10-29T20:21:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiagogwillecke](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/thiagogwillecke/32/1669_2.png) [@thiagogwillecke](https://qa.fmod.com/u/thiagogwillecke)\
**Post date:** [October 29, 2020, 8:21pm UTC](https://qa.fmod.com/t/different-terrains-script-unity-parameter-doesnt-change/16378/1 "2020-10-29T20:21:32Z")

</div>

Hi, I’m having issues with my attempt to implement footsteps for different terrains using Unity and FMOD. The footsteps are triggered by animation events, but I can hear only one kind of terrain when playing. I guess there’s something wrong with the script that is not changing the parameters in FMOD.

I’m using a script by Alessando Fama footsteps guide ([alessandrofama.com/tutorials/fmod-unity/footsteps/unity/footsteps/](http://alessandrofama.com/tutorials/fmod-unity/footsteps/unity/footsteps/)). Here it is:

using System.Collections;  
using System.Collections.Generic;  
using UnityEngine;  
public class PlayerFootsteps : MonoBehaviour {  
private enum CURRENT\_TERRAIN { GRASS, GRAVEL, WOOD\_FLOOR, WATER };  
[SerializeField]  
private CURRENT\_TERRAIN currentTerrain;  
private FMOD.Studio.EventInstance foosteps;  
private void Update()  
{  
DetermineTerrain();  
}  
private void DetermineTerrain()  
{  
RaycastHit[] hit;  
hit = Physics.RaycastAll(transform.position, Vector3.down, 10.0f);  
foreach (RaycastHit rayhit in hit)  
{  
if (rayhit.transform.gameObject.layer == LayerMask.NameToLayer(“Gravel”))  
{  
currentTerrain = CURRENT\_TERRAIN.GRAVEL;  
break;  
}  
else if (rayhit.transform.gameObject.layer == LayerMask.NameToLayer(“Wood”))  
{  
currentTerrain = CURRENT\_TERRAIN.WOOD\_FLOOR;  
break;  
}  
else if (rayhit.transform.gameObject.layer == LayerMask.NameToLayer(“Grass”))  
{  
currentTerrain = CURRENT\_TERRAIN.GRASS;  
}  
else if (rayhit.transform.gameObject.layer == LayerMask.NameToLayer(“Water”))  
{  
currentTerrain = CURRENT\_TERRAIN.WATER;  
}  
}  
}  
public void SelectAndPlayFootstep()  
{  
switch (currentTerrain)  
{  
case CURRENT\_TERRAIN.GRAVEL:  
PlayFootstep(1);  
break;  
case CURRENT\_TERRAIN.GRASS:  
PlayFootstep(0);  
break;  
case CURRENT\_TERRAIN.WOOD\_FLOOR:  
PlayFootstep(2);  
break;  
case CURRENT\_TERRAIN.WATER:  
PlayFootstep(3);  
break;  
default:  
PlayFootstep(0);  
break;  
}  
}  
private void PlayFootstep(int terrain)  
{  
foosteps = FMODUnity.RuntimeManager.CreateInstance(“event:/Footsteps”);  
foosteps.setParameterByName(“Terrain”, terrain);  
foosteps.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));  
foosteps.start();  
foosteps.release();  
}  
}

The ground objects are assigned to layers according to the script. But I can only hear the sounds coming from Parameter = 0 in the game, even though I’ve added different grounds in different layers. Is there something wrong with the code?

I’m using FMOD 2.00.10 and Unity 2020.1.10

---

<div class="post-metadata">

**Author:** ![alexzzen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexzzen/32/6825_2.png) [@alexzzen](https://qa.fmod.com/u/alexzzen)\
**Post date:** [October 30, 2020, 1:01pm UTC](https://qa.fmod.com/t/different-terrains-script-unity-parameter-doesnt-change/16378/2 "2020-10-30T13:01:53Z")

</div>

Thanks for referring to my tutorial, but I can’t reproduce the problem in my example project, can you share a minimal project where the problem occurs? Keep in mind this is a Unity & programming question, not a problem about FMOD or the Unity integration.

---

<div class="post-metadata">

**Author:** ![thiagogwillecke](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/thiagogwillecke/32/1669_2.png) [@thiagogwillecke](https://qa.fmod.com/u/thiagogwillecke)\
**Post date:** [October 30, 2020, 4:55pm UTC](https://qa.fmod.com/t/different-terrains-script-unity-parameter-doesnt-change/16378/3 "2020-10-30T16:55:41Z")

</div>

Hi Alex, thanks for your reply and I apologize for misunderstanding the kind of problem I’ve got. The issue is that the footsteps sounds aren’t changing, even though my ground objects are assigned to respective layers, as in your guide. Debugging tells that the Terrain parameter changes inside Unity. But for some reason, it doesn’t change the sound module being played. It’s like Unity can’t talk to my FMOD when it comes to this parameter. I’ve tried to use your tutorial’s Fmod project and I face the same issue. It only playbacks Parameter = 0 sounds, despite the terrain.

[Here’s my Unity Project](https://www.dropbox.com/s/876g9a82kubq33v/SFX_Template.rar?dl=0)  
[Here’s my FMOD Project](https://www.dropbox.com/s/dt3tpjsgjc9nea9/FMOD_Project.rar?dl=0)

---

<div class="post-metadata">

**Author:** ![alexzzen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexzzen/32/6825_2.png) [@alexzzen](https://qa.fmod.com/u/alexzzen)\
**Post date:** [October 30, 2020, 7:42pm UTC](https://qa.fmod.com/t/different-terrains-script-unity-parameter-doesnt-change/16378/4 "2020-10-30T19:42:55Z")

</div>

Change the function the animation events call from PlayFootstep to SelectAndPlayFootstep, then it will work. Cheers and happy developing 🙂

---

<div class="post-metadata">

**Author:** ![thiagogwillecke](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/thiagogwillecke/32/1669_2.png) [@thiagogwillecke](https://qa.fmod.com/u/thiagogwillecke)\
**Post date:** [October 30, 2020, 10:33pm UTC](https://qa.fmod.com/t/different-terrains-script-unity-parameter-doesnt-change/16378/5 "2020-10-30T22:33:47Z")

</div>

It works! My man… I really was looking forward to have that working. Thank you so much… And thank you for all your tutorials, I’m learning a lot from them!
