Assets/Plugins/Editor/CreateAssetbundles.cs(49,17): error CS0103: The name `anim' does not exist in the current context

with my last question was fixed a new problem came up.

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

class CreateAssetbundles
    // This method creates an assetbundle of each SkinnedMeshRenderer
    // found in any selected character fbx, and adds any materials that
    // are intended to be used by the specific SkinnedMeshRenderer.
    [MenuItem("Character Generator/Create Assetbundles")]
    static void Execute()
        bool createdBundle = false;
        foreach (Object o in Selection.GetFiltered(typeof (Object), SelectionMode.DeepAssets))
            if (!(o is GameObject)) continue;
            if ("@")) continue;
            if (!AssetDatabase.GetAssetPath(o).Contains("/characters/")) continue;

            GameObject characterFBX = (GameObject)o;
            string name =;
            Debug.Log("******* Creating assetbundles for: " + name + " *******");

            // Create a directory to store the generated assetbundles.
            if (!Directory.Exists(AssetbundlePath))

            // Delete existing assetbundles for current character.
            string[] existingAssetbundles = Directory.GetFiles(AssetbundlePath);
            foreach (string bundle in existingAssetbundles)
                if (bundle.EndsWith(".assetbundle") && bundle.Contains("/assetbundles/" + name))

            // Save bones and animations to a seperate assetbundle. Any 
            // possible combination of CharacterElements will use these
            // assets as a base. As we can not edit assets we instantiate
            // the fbx and remove what we dont need. As only assets can be
            // added to assetbundles we save the result as a prefab and delete
            // it as soon as the assetbundle is created.
            GameObject characterClone = (GameObject)Object.Instantiate(characterFBX);

			// postprocess animations: we need them animating even offscreen
			foreach (Animation cullingType in characterClone.GetComponentsInChildren<Animation>())
                anim.cullingType = AnimationCullingType.AlwaysAnimate;

            foreach (SkinnedMeshRenderer smr in characterClone.GetComponentsInChildren<SkinnedMeshRenderer>())
            Object characterBasePrefab = GetPrefab(characterClone, "characterbase");
            string path = AssetbundlePath + name + "_characterbase.assetbundle";
            BuildPipeline.BuildAssetBundle(characterBasePrefab, null, path, BuildAssetBundleOptions.CollectDependencies);

            // Collect materials.
            List<Material> materials = EditorHelpers.CollectAll<Material>(GenerateMaterials.MaterialsPath(characterFBX));

            // Create assetbundles for each SkinnedMeshRenderer.
            foreach (SkinnedMeshRenderer smr in characterFBX.GetComponentsInChildren<SkinnedMeshRenderer>(true))
                List<Object> toinclude = new List<Object>();

                // Save the current SkinnedMeshRenderer as a prefab so it can be included
                // in the assetbundle. As instantiating part of an fbx results in the
                // entire fbx being instantiated, we have to dispose of the entire instance
                // after we detach the SkinnedMeshRenderer in question.
                GameObject rendererClone = (GameObject) PrefabUtility.InstantiatePrefab(smr.gameObject);
                GameObject rendererParent = rendererClone.transform.parent.gameObject;
                rendererClone.transform.parent = null;
                Object rendererPrefab = GetPrefab(rendererClone, "rendererobject");

                // Collect applicable materials.
                foreach (Material m in materials)
                    if ( toinclude.Add(m);

                // When assembling a character, we load SkinnedMeshRenderers from assetbundles,
                // and as such they have lost the references to their bones. To be able to
                // remap the SkinnedMeshRenderers to use the bones from the characterbase assetbundles,
                // we save the names of the bones used.
                List<string> boneNames = new List<string>();
                foreach (Transform t in smr.bones)
                string stringholderpath = "Assets/bonenames.asset";
				StringHolder holder = ScriptableObject.CreateInstance<StringHolder> ();
				holder.content = boneNames.ToArray();
                AssetDatabase.CreateAsset(holder, stringholderpath);
                toinclude.Add(AssetDatabase.LoadAssetAtPath(stringholderpath, typeof (StringHolder)));

                // Save the assetbundle.
                string bundleName = name + "_" +;
                path = AssetbundlePath + bundleName + ".assetbundle";
                BuildPipeline.BuildAssetBundle(null, toinclude.ToArray(), path, BuildAssetBundleOptions.CollectDependencies);
                Debug.Log("Saved " + bundleName + " with " + (toinclude.Count - 2) + " materials");

                // Delete temp assets.
                createdBundle = true;

        if (createdBundle)
            EditorUtility.DisplayDialog("Character Generator", "No Asset Bundles created. Select the characters folder in the Project pane to process all characters. Select subfolders to process specific characters.", "Ok");

    static Object GetPrefab(GameObject go, string name)
        Object tempPrefab = PrefabUtility.CreateEmptyPrefab("Assets/" + name + ".prefab");
        tempPrefab = PrefabUtility.ReplacePrefab(go, tempPrefab);
        return tempPrefab;

    public static string AssetbundlePath
        get { return "Assets" + Path.DirectorySeparatorChar + "assetbundles" + Path.DirectorySeparatorChar; }

Your lines 43-44

 foreach (Animation cullingType in characterClone.GetComponentsInChildren<Animation>())
        anim.cullingType = AnimationCullingType.AlwaysAnimate;

==> anim is not defined, and in your logic you would have to call cullingType.cullingType ^^;

I think you got a little ahead of yourself and meant to write:

  foreach (Animation anim in characterClone.GetComponentsInChildren<Animation>())
        anim.cullingType = AnimationCullingType.AlwaysAnimate;

There is no such thing as ‘anim’ being defined anywhere thus it errors, it pretty much says as much

Should it not just be:

foreach (Animation anim in characterClone.GetComponentsInChildren<Animation>())
    anim.cullingType = AnimationCullingType.AlwaysAnimate;

minus the anim at the beginning