- Home /
"Use of unassigned local variable" error that seems wrong
Unity is protesting. It gives me the error: Use of unassigned local variable `att'. It gives the error for the return-line, not for the line in the if-statement.
In some cases like if you have a local variable declaration inside a code-block you can sometimes get this error, but I can't see how this function can not see the declaration. Anyone have any ideas? What am I not seeing? Thanks!
public cBaseStats GetAttribute(string name)
{
int cnt;
cBaseStats att = new cBaseStats();
for (cnt = 0; cnt < _attrib.Length; cnt++)
{
if (_attrib[cnt].Name == name)
att = _attrib[cnt];
}
return att;
Comment
I created a test project for this and it works fine for me. The code you pasted is missing the closing brace. Was that just a copy & paste issue, or is it missing in your code too?