- Home /
An object reference is required to acess non-static member.
So I have an array of structs :
public LevelInf[] levels;
inside of the class "GameInfo"
public class GameInfo : MonoBehaviour {
which is made static by a child variable
public static GameInfo info;
however, when I try to access the array of structs in another script,
if(GameInfo.levels[level].speed) {
I get the "An object reference is required to access non-static member". I've know what this error is saying, and I know that there is a huge google results page of this question, but I don't know why I'm getting it, as "GameInfo" is indeed a static member. Additionally, I can't make the struct array static, as I need to change it's values in the inspector.
Answer by cjdev · Aug 09, 2015 at 05:43 AM
The child variable is static but the class itself isn't and it's non-static member is 'levels'. To fix it you have to create an instance of the object so that you can reference it with your variable:
void Start()
{
info = new GameInfo();
}
Thank you! Funilly (is that a word?) enough, I figured that out like 2 $$anonymous$$utes before I saw your answer. Thanks anyway, though.