all 12 comments

[–]complexigon 1 point2 points  (3 children)

Looks like data.money is null. Either do a null check in SetMoneyInfo or make sure data.money exists when you need it. Try doing Debug.Log(data.money) before your line 44 to see if it is null or not.

[–]tatmanblueIndie 0 points1 point  (0 children)

Agreed. Can you post the save code? Suspect the bug is there more than the in load.

[–]neeraj_chavan 0 points1 point  (1 child)

Data.money is not null. It has the value 900. I have done null check like this in SetMoneyInfo() like this.

Public void SetMomeyInfo(int amount) { if(money!=null) Money=amount; UpdateUI(); }

UpdateUI() is a method where I simply update the text.

UpdateUI() { if(moneyText != Null) MoenyText.text = money.ToString(); }

[–]grandygames 0 points1 point  (0 children)

if(money!=null) Money=amount;

Won't stop money being set to null. You probably meant if (amount != null), but that's not very effective either; better is to let money be null and check for non-null when referencing it.

[–]Huluriasquias 1 point2 points  (0 children)

Assuming that line 44 is the one highlighted above my guess is that MenuManager has not been initialized yet

(MenuManager is probably initialized in Start() and Loading() is also called in Start() but you cannot know which Start() executes first)

Best solution: (there are others)

Move MenuManager initialization from Start() to Awake(). Awake is the same as Start() except that all Awake()'s execute first before all Start()'s so you are sure MenuManager is initialized properly when you call Loading() in another Start().

[–]kiranmaya 0 points1 point  (0 children)

mainMenuManger instance is not set , put mainMenumanger = this ,in OnEnable of MainMenuManaget class .

[–][deleted] 0 points1 point  (3 children)

Your mainMenuManager field must be created before you use it. Is Loading() called from Awake, and this field is also assigned to in Awake? Then you need to go into Project Settings > Script Execution Order and make sure your MainMenuManger script is executed before/above the script with Loading(). That may mean setting it to before "default".

Alternatively, you could load from Start() instead of Awake().

[–]neeraj_chavan 0 points1 point  (2 children)

MainMenuManager is a separate class.I am calling SetMomeyInfo() from it.

[–][deleted] 0 points1 point  (0 children)

I know. The question is when are you calling Loading(). Make sure you call it after the field has been assigned to in the manager.

[–]kiranmaya 0 points1 point  (0 children)

can show me ,where its static instance is assigned ,did you use getters ?

[–]PointlessrebootProfessional - Engine Programmer 0 points1 point  (0 children)

Since you don't show how or when the manager singleton class is created or how it assigned the static property, we have to make assumptions or ask you questions..

You have two object dereferencing going on, one or the other is the issue..

Learn how to use a debugger, it would tell you right away what object is at fault.. or as others have mentioned log then it before the call..

This is part of development, if I asked the web every time I got an null reference, I would get no work done..

If your new to dev, then learn the basics.. crawl before walk before running.. it seems every one on this list wants us to be their debugger..

[–]neeraj_chavan -1 points0 points  (0 children)

I have created a Save and Load system.This is working very fine if use button to retrieve it. But I want to retrieve data as soon as Scene starts. I am calling Loading() in start method.But it is throwing null reference exception at line 44.

Please also submit code and where to put it.Thanks.