Problem saving UMA avatar to text file via button onClick.
I'm using UMA with Unity 5, and have a problem with the saving of my generated avatar. I have two scenes, one to generate a character, the other is the first in-game scene. In the character generation scene, I have a UMACrowd script attached to my UMACrowd object, and this script has "save" and "load" checkboxes in the Inspector window (from the Secret Anorak tutorials). I can configure my character and successfully save it to a text file by checking the "save" box (which calls a Save method in the UMACrowd script), and then when I load my game scene, the character I just created loads perfectly. The problem is when I try to link that same Save method to a button, so the user can generate the character and then click a "Create" button to save to a text file. I created a game object and linked the script to it, but I've no luck in making the Save method work with the button's OnClick event. The error I get is: "NullReferenceException: Object reference not set to an instance of an object UMACrowd.Save ()". It's the EXACT same script that the successfully-working Save checkbox works with. Below is the relevant code. Can anyone help?
public void Save()
{
// Generate UMA string.
UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
recipe.Save(umaDynamicAvatar.umaData.umaRecipe, umaDynamicAvatar.context);
SaveString = recipe.recipeString;
Destroy(recipe);
// Save the string to a text file.
string fileName = "Assets/test.txt";
StreamWriter stream = File.CreateText(fileName);
stream.WriteLine(SaveString);
stream.Close();
}