Loading Breaks Public References

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Aephrosi
Posts: 4
Joined: Fri Nov 08, 2024 9:35 pm

Loading Breaks Public References

Post by Aephrosi »

Whenever I load (currently with SaveSystemMethods) I am getting:

Code: Select all

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
On public references that are visible in the inspector. This only seems to happen on functions that are called through Lua.RegisterFunction.
SaveBroken.png
SaveBroken.png (67.69 KiB) Viewed 48 times
If I do a:

Code: Select all

player = GameObject.Find("Player")
before trying to use it, everything proceeds just fine. Problem is, I have many other game objects that need to maintain that reference.

Thanks in advance.
Aephrosi
Posts: 4
Joined: Fri Nov 08, 2024 9:35 pm

Re: Loading Breaks Public References

Post by Aephrosi »

Can confirm that it looks like it has to do with running it straight through the Lua.RegisterFunction call.

If I instead have the dialogue system enable an separate object with a Usable trigger, I can go to that object to trigger the code with the usable.
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading Breaks Public References

Post by Tony Li »

Hi,

It may be related to Don't Destroy On Load GameObjects such as the Dialogue Manager. Please see: How To: Manage Player Controls and Scene Changes for an explanation (with images) of what I mean.
Aephrosi
Posts: 4
Joined: Fri Nov 08, 2024 9:35 pm

Re: Loading Breaks Public References

Post by Aephrosi »

Great! thank you. I'll stay with my work-around for now, but if I end up needing this, it's good to have as a reference.
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading Breaks Public References

Post by Tony Li »

Sounds good!
Post Reply