Variable won't update within a certain function

Hey guys,

Not sure this is exactly the right forum for this but it involves FMOD and Unity so i figured i’d put it here.
I’m having a bit of fun with the Angry Bots project and the FMOD intergration provided by Sound Librarian http://www.soundlibrarian.com/uploads/3 … torial.pdf

I’ve been trying to automate the footsteps so that they sound different depending on whether the player is outside or inside. Here’s my code so far

#pragma strict

class FootstepHandler extends MonoBehaviour 
{

enum FootType 
{
	Player,
	Mech,
	Spider
}

public var audioSource : AudioSource;
public var footType : FootType;

private var evt : FMOD.Studio.EventInstance;
private var param : FMOD.Studio.ParameterInstance;
private var attributes : FMOD.Studio._3D_ATTRIBUTES;

public var isOutside = true;

public var physicMaterial : PhysicMaterial;

private var eventPath : String;

static var sInstance : FootstepHandler = null;
	static function instance() : FootstepHandler
	{
		return sInstance;
	}
	
	function Awake()
	{
		sInstance = this;		
	}
															
																		
function OnCollisionEnter (collisionInfo : Collision) 
{
	physicMaterial = collisionInfo.collider.sharedMaterial;		
}


function OnFootstep () 
{	 
	switch (footType) 	
	{
	case FootType.Player:
		eventPath = MaterialImpactManager.GetPlayerFootstepSound(physicMaterial);
		break;
	case FootType.Mech:
		eventPath = MaterialImpactManager.GetMechFootstepSound(physicMaterial);
		break;
	case FootType.Spider:
		eventPath = MaterialImpactManager.GetSpiderFootstepSound(physicMaterial);
		break;
	}	
	
	if (!String.IsNullOrEmpty(eventPath))
	evt = FMOD_StudioSystem.instance.GetEvent(eventPath);
	attributes = FMOD.Studio.UnityUtil.to3DAttributes(transform.position);
	evt.set3DAttributes(attributes);
	evt.getParameter("Wet", param);	
		
	param.setValue(isOutside ? 1.0f : 0.0f);
				
	evt.start();
	evt.release();		
															
}
																													
public function setOutside(outside : boolean)
{
	isOutside = outside;
	print("Footstep Transition: " + (outside ? "Outside" : "Inside"));
}		
			
}
		

Angry Bots is using ‘MoodBoxes’ to trigger changes when the player walks through them. In the script above, the function setOutside() is using data from those MoodBoxes (in another script) to switch between Inside and Outside. The value is assigned to a boolean variable called isOutside, and that value is then used to modify the FMOD parameter within the OnFootstep() function (which is triggering the FMOD event).

Here’s my problem though: the isOutside variable won’t update within the OnFootstep() function. It works fine within setOutside(), and Update() for example but not in OnFootstep(). I checked using the console.

Anyone has any idea how I could pass that value to the right function, or do anything to make it work?
Hopefully it’s something quite easy or obvious i’m missing, but I’ve been pulling my hair out on this one and here’s hoping someone can help.

Thanks in advance and let me know if you need any more detail.

   param.setValue(isOutside ? 1.0f : 0.0f);

If you’re talking about this line, it just passing the isOutside through to FMOD not actually changing it’s value. If you take a look at the setOutside function it assigned the passed in value then passes it through to FMOD. If you call setOutside(true) twice, the second time it will have no effect as FMOD parameter value wont change. I hope that answers your question if not please elaborate on what part of the code is not behaving as you expect.

Hi peter,

Thanks for your help, and sorry if I’m unclear, but being kind of a newbie I lack the precise vocabulary to describe in detail what I mean.

The problem is not the value not being passed to FMOD, but rather the isOutside variable not updating within the OnFootstep() function.

The ‘outside’ boolean switches between true and false depending on the player’s position. This line

print("Footstep Transition: " + (outside ? "Outside" : "Inside"));

allows me to check that it is updated normally and works fine. I assign ‘isOutside’ to ‘outside’ which means isOutside should now update according to the player’s position.

Now if i print to console within the Update() function using this line :

print("isOutside Check: " + (isOutside ? "True" : "False"));

, I can confirm that isOutside switches normally between true and false and works fine. But the same print line within the OnFootstep() function shows that ‘isOutside’ is not being updated at all and doesn’t switch between true and false. And i’ve no idea why…