- Home /
an object reference is required for the non static field error
Hello, I'm trying to set a state in another script:
// Rubber Spider
private enum RubberSpiderQuest
{
not_started,
started,
complete
}
private RubberSpiderQuest myRubberSpiderQuest;
public static void startRubberSpiderQuest()
{
myRubberSpiderQuest = RubberSpiderQuest.started;
}
Something like that: In my main script I'm trying to do this:
// Save Quest State
UserInformation.startRubberSpiderQuest();
But In my UserInformation script I get the following error:
An object reference is required for the non-static field, method, or property 'UserInformation.myRubberSpiderQuest'
Any idea how I correct this?
Answer by Kishotta · Jul 01, 2017 at 04:39 PM
The issue is, because you've made startRubberSpiderQuest()
static, it doesn't know which RubberSpider instance's myRubberSpiderQuest
to set. myRubberSpiderQuest
should be declared static as well. Otherwise, you will need to pass a RubberSpider
object into the starter method.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Couldn't find a key match for _gv.Inventory 1 Answer
Calling non-static from static function C# 2 Answers
Player movement isn't working 1 Answer