- Home /
help with error CS0029: Cannot implicitly convert type `bool'
hey If anyone can help I would really appreciate so the problem is:
error CS0029: Cannot implicitly convert type bool' to
UnityEditor.ModelImporterClipAnimation[]'
this is the line were the error is :
ModelImporter modelImporter = ModelImporter.GetAtPath(assetPath) as ModelImporter; modelImporter.clipAnimations = true; modelImporter.generateAnimations = ModelImporterGenerateAnimations.InRoot;
this is the whole function:
void ProcessAnimations(GameObject DestinationAsset, string objectName, XmlDocument doc, int total) { Debug.Log("Starting animation split process..."); string assetPath = AssetDatabase.GetAssetPath(DestinationAsset);
if (assetPath.Contains(objectName))
{
ModelImporter modelImporter = ModelImporter.GetAtPath(assetPath) as ModelImporter;
modelImporter.clipAnimations = true;
modelImporter.generateAnimations = ModelImporterGenerateAnimations.InRoot;
// Set the number of animations here
int numAnimations = total;
ModelImporterClipAnimation[] animations = new ModelImporterClipAnimation[numAnimations];
XmlNodeList list = doc.GetElementsByTagName("Data");
int i = 0;
foreach (XmlNode node in list)
{
XmlAttributeCollection child = node.Attributes;
string name = "";
int sf = 0;
int ef = 0;
foreach (XmlNode nd in child)
{
if (nd.Name == "name")
name = nd.Value;
if (nd.Name == "startFrame")
sf = int.Parse(nd.Value.Replace("f", ""));
if (nd.Name == "endFrame")
ef = int.Parse(nd.Value.Replace("f", ""));
}
bool loop = false;
string nm = name.ToLower();
if (nm.Contains("idle") || nm.Contains("walk") || nm.Contains("sprint") || nm.Contains("run") || nm.Contains("strafe"))
loop = true;
animations[i] = SetClipAnimationNew(nm, sf, ef, loop);
i++;
}
modelImporter.clipAnimations = animations;
Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject));
EditorUtility.SetDirty(asset);
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
}
}
private ModelImporterClipAnimation SetClipAnimationNew(string name, int firstFrame, int lastFrame, bool loop)
{
ModelImporterClipAnimation mica = new ModelImporterClipAnimation();
mica.name = name;
mica.firstFrame = firstFrame;
mica.lastFrame = lastFrame;
mica.loop = loop;
if (loop)
mica.wrapMode = WrapMode.Loop;
else
mica.wrapMode = WrapMode.Once;
return mica;
}
}
Answer by robertbu · Oct 16, 2013 at 07:05 AM
Your issue is on line 4:
modelImporter.clipAnimations = true;
'clipAnimations' is not a boolean value. It is defined as 'ModelImporterClipAnimation[]'.
http://docs.unity3d.com/Documentation/ScriptReference/ModelImporter-clipAnimations.html
Stop trying to assign a boolean to a non-boolean variable.
I mean could you help me rewrite the script that is above?
As a guess, try commenting the line out. I did not take the time to understand all the code here, but '.clipAnimations' is assigned on line 40, and nothing in the function accesses it before line 40.
didn't help :/ maybe should I give a whole script ? I really need this for my college project :/
Your answer
![](https://koobas.hobune.stream/wayback/20220613120020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Convert type `float' to `bool', Load 1 Answer
Get Component Error 0 Answers
Cannot implicitly convert type 'float' to 'bool' 3 Answers
Bool script error 1 Answer
Unit stops responding when i import models. WHY??? 2 Answers