How to Reset the Lua Environment?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
WeiYiHua
Posts: 13
Joined: Mon Mar 25, 2024 10:27 pm

How to Reset the Lua Environment?

Post by WeiYiHua »

Hello!

I’m using Dialogue System, and I’ve noticed that after exiting and loading a saved game, many unrelated assets remain loaded in memory. These include Texture, SpriteAtlas, DialogueDatabase instances, etc. After some investigation, I found that even after exiting the saved game and unloading the scene, some static dictionaries in the Lua environment are still holding references to these objects.

I tried calling methods similar to InitStaticVariables in the LuaInterpreter and Lua classes during unloading. As a result, those assets were no longer referenced and could be unloaded properly. (Calling DatabaseManager.Clear alone did not have this effect.)

Did I miss anything? If calling methods like InitStaticVariables is the correct approach, could you consider adding some similar public methods? Thank you!
User avatar
Tony Li
Posts: 23379
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to Reset the Lua Environment?

Post by Tony Li »

Hi,

Depending on what you want to clear, you can call DialogueManager.RemoveDatabase() to remove databases from memory that you added during play, or call SaveSystem.ResetGameState() to clear the saved game data in memory -- however, you shouldn't need this latter method if you're loading a saved game, since that will also clear and reload the saved game data.
Post Reply