Cannot access non-static method in static context?
I'm creating a JSON saving system for my unity game right now. I've already made one before that worked perfectly fine so I just copied that script over, but whenever I try to save data, I get "Cannot access non-static method 'SaveData' in static context" in Rider and Unity says "An object reference is required for the non-static field, method, or property 'JSONHandler.SaveData(int, int)'". The JSON saving script is not static and the script that it's getting called from is also not static. It also looks identical to the other game but does not work here.
12 Replies
but you have not created the object 😐
like
thats weird i didnt have to do that in the other game
unless im just blind
ur method is probably static in the other game
and besides this is Unity, you can't just use
new
on a class that inherits from Component
you need to add the component to a gameobject firstit is on a gameobject tho
then access the JsonHandler that is attached to that gameobject
ive already done that
not according to your image
ok thats weird then
ill try creating a new script and reattaching it
i dont see why you would do that
you said its attached to that gameobject
so just get the reference of that gameobject
where is FinishGame defined?
i have no idea why but it works now
it seems there was a problem with the file or something because i just copy pasted the code into a new script and it worked
you didn't modify anything?
no