- Home /
Can no longer get Array length?
I had a script that's been working fine, the only thing that's been different is I changed it to Monobehaviour. After I've done this I can no longer get the length of my arrays. I can still access the arrays as if they are, but I cant get their length anymore. The Array.length option doesn't even show up in the tips while typing. And if I type it anyway I'll get "unresolved member" error when I scroll over it. And in Unity I get: Assets/Scripts/Player/AttackClass.cs(79,46): error CS1061: Type ComboFrames[]' does not contain a definition for
length' and no extension method length' of type
ComboFrames[]' could be found (are you missing a using directive or an assembly reference?)
public class AttackClass : MonoBehaviour
{
public ComboFrames[] GroundCombo;
public ComboFrames[] AirCombo;
//Ints that hold the max number of combos for the attacks.
private int maxCombo;
private int maxComboGround;
public int[] testing;
void Awake()
{
Debug.Log(testing.Length);
Debug.Log(GroundCombo[0].start);
maxComboGround = GroundCombo.Length;
Debug.Log(maxComboGround);
}
}
[System.Serializable]
public class ComboFrames
{
public int start;
public int active;
public int ending;
/// <summary>
/// Amount of frames allowed for input into next combo.
/// </summary>
public int combo;
}
The GroundCombo[0].start works just fine, so its an Array and it exists... However 'length' or any other array extensions just aren't there. The 'testing' integer array works fine with the extensions. Do class arrays not work with array extensions when you're using Monobehaviour? Are there any work arounds?
Update: Stopped having a problem and was working fine, then it suddenly stopped working again. What I noticed is when I scroll over a declaration of GroundCombo and the tooltip comes up. It doesn't show ComboFrames[] like it would with testing showing int[], it just shows up ComboFrames as if it isn't even an array, just a single instance. Seems like this is more of an issue with MonoDev than Unity. This question can be closed.
sometimes, while you are coding and you start a curly brace, lets say
if (val < targetVal)
{
monodevelop will get really fussy about the curly brace not being closed. it is, therefore good practice to close it BEFORE you write any code inside the curly braces
if (val < targetVal)
{
}
//now you can write code
if (val < targetVal)
{
//do something awesome
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613104208im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Gun Class with Array List of Projectiles 2 Answers
Why Again Arrays In ExecuteInEditMode() Gives NullReferenceException Errors?? 1 Answer
Classes : extend MonoBehaviour issues 1 Answer
Material Array list and its .length not working/showing in dropdown menu 1 Answer
Is for loop caching worth it in unity3d Mono Develop 1 Answer