Null Reference Exception when storing a reference to object

Discussion and help for Easy Save 3
Post Reply
EasySaveUser
Posts: 3
Joined: Thu May 16, 2019 2:14 pm

Null Reference Exception when storing a reference to object

Post by EasySaveUser »

Hello all,

I've been trying to use the AutoSave feature to implement saving and loading in my game, and had no problems when it came to testing in a basic scene. However, I'm running into an error when trying to implement it to actually save the game. There's a "Player" monobehaviour class which keeps a reference to a "Vertex" monobehaviour class which I've implemented. The Vertex class is a monobehaviour class and Prefab which I instantiate at runtime elsewhere in the code.

Code: Select all

public class OverworldPlayer : MonoBehaviour {
public Vertex currentVertex;
...
public Void SetVertex(Vertex inVertex)
{
currentVertex = inVertex
}
This works perfectly well while the game is running, but I run into problems after trying to save and reload the scene, and more specifically, the Overworld Player (I have AutoSave "Save Event = On Application Quit" and "Load Event = Awake"). When I reload the scene, I run into a "Null Reference Exception" and "currentVertex" remains Null. I'm really not sure what I'm missing here, any ideas? Thanks :)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Null Reference Exception when storing a reference to obj

Post by Joel »

Hi there,

Just to check, have you followed the Saving and Loading Prefab Instances instructions on this page for the GameObjects containing your Vertex classes? Otherwise they will not be added to the reference manager and Easy Save will have no way of knowing that they exist.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
EasySaveUser
Posts: 3
Joined: Thu May 16, 2019 2:14 pm

Re: Null Reference Exception when storing a reference to obj

Post by EasySaveUser »

Joel,

Yes, I followed the steps listed on the link you provided. For reference, the "Vertex" gameobject components: Transform, Sprite Renderer, Circle Collider 2D, Vertex (Script), ES3 Prefab (Script), ES3 Autosave (Script). I'm not sure if it's relevant, but I've tried toggling "Auto Update References" on and off in the EasySave Editor Settings, but it didn't appear to make any difference. What do you think is going on here?

Thanks :)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Null Reference Exception when storing a reference to obj

Post by Joel »

Hi there,

Unfortunately it's not possible for me to tell based on what you've said. Please could you create a basic project and instructions to replicate it and PM them to me so I can try it at my end?

Thanks,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
EasySaveUser
Posts: 3
Joined: Thu May 16, 2019 2:14 pm

Re: Null Reference Exception when storing a reference to obj

Post by EasySaveUser »

PM'd
Post Reply