- Home /
Question by
raze incorporated · Nov 20, 2013 at 10:00 PM ·
c#error messagecs0120
error CS0120
Assets/GameContent/Motiontracks/Editor/AnimationImporter.cs(25,39): error CS0120: An object reference is required to access non-static member `UnityEditor.ModelImporter.clipAnimations'
I was trying import animations and came upon an error. I really need your help, because I'm new to C# coding. Anyways, the error is in line 16 Here's the code:
class ImportAnimationsClips : AssetPostprocessor
{
public static void Process(GameObject DestinationAsset, string objectName, XmlDocument doc, int total)
{
ImportAnimationsClips clips = new ImportAnimationsClips();
clips.ProcessAnimations(DestinationAsset, objectName, doc, total);
}
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.clipAnimations = ModelImporter.GetAtPath(assetPath);
// 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++;
}
Comment
Answer by GameVortex · Nov 20, 2013 at 10:15 PM
The problem is that the variable "clipAnimations" is not static and you can therefore as the error says not access it without an object reference. You probably want to do something like this:
ModelImporter modelImporter = ModelImporter.GetAtPath(assetPath) as ModelImporter;
//Then you can access the clipAnimations through the object reference like this:
ModelImporterClipAnimation[] clipAnimations = modelImporter.clipanimations;
Your answer
Follow this Question
Related Questions
Error CS1525: Unexpected symbol `}' 1 Answer
Access to path /???? is denied on Mac OS 2 Answers
error CS1525: Unexpected symbol `}' 0 Answers
Problem with score in C# 1 Answer