Issue with loading scenes from saves

The engine is not working as expected? Documentation is wrong or out of date? Let us know here!
Forum rules
We are not providing support via this forum; it's community-driven. For official support see https://naninovel.com/support/#naninovel-support
Post Reply
ZeRAWDOG
Posts: 3
Joined: 01 Oct 2022 04:09

Issue with loading scenes from saves

Post by ZeRAWDOG »

Hello, I've been making my own point and click adventure game in Naninovel, and ran into a bit of a massive issue. I've designed the game around loading Scene environments for each room of a spaceship, and although I have the loading correctly between labels my issue is how Naninovel loads the saves. From my own research on the forums Naninovel doesn't actually save Scenes when you use the @Loadscene command, and since my game is built around this it's become a serious problem that I needed help with.

My main question is: How do I get Naninovel to remember the scene in a save and load back into the game into it?

For reference my code for the rooms is formatted like this in the labels:

Label# Bathroom (label just for formatting on this forum)
@ColliderReset
@loadScene Bathroom additive:true if:{activeScene}!=Bathroom
@unloadScene {activeScene} if:{activeScene}!=Bathroom
@set activeScene="Bathroom"
@hideAll
@toast "Bathroom" time:3
@stop

To test I had made a save at this point where a room was loaded. If the game had loaded from the label it would have had a chance to load the scene, but it gets confused and just keeps the scene loaded from the menu. When you roll back just one click it reloads but I have rollback disabled since I didn't want players constantly reloading scenes. Is there a way to change the loading to include my {activeScene} variable to load on load?

idaot
support
Posts: 275
Joined: 01 Aug 2020 08:25

Re: Issue with loading scenes from saves

Post by idaot »

You'll need to create a custom state for the scenes if you plan to save them: https://naninovel.com/guide/custom-acto ... stom-state

However, my recommendation is to not use scenes for naninovel gameplay unless there's some custom gameplay integration involved. Rather, consider using generic backgrounds which has almost all the benefits of a scene with states already added and has a lot of flexibility options. https://naninovel.com/guide/backgrounds ... ackgrounds

ZeRAWDOG
Posts: 3
Joined: 01 Oct 2022 04:09

Re: Issue with loading scenes from saves

Post by ZeRAWDOG »

So our build is primarily playing in Scene environments so it's absolutely necessary for scenes to be used.

My biggest confusion is the specific code in the API for loading scene on load, because that's what's preventing. What I'm imagining the solution is to retrieve {activeScene} variable and on save load load that scene name, but I'm having trouble figuring out what the actual bit of code I'm looking for is. I'm assuming it has something to do with State management, but the issue is specifically on Nani save load to @loadScene with {currentScene} name, or simply to remember what the last scene was and load from there.

idaot
support
Posts: 275
Joined: 01 Aug 2020 08:25

Re: Issue with loading scenes from saves

Post by idaot »

Alternatively, consider making a custom background implementation with SceneBackground.cs as the basis. I imagine there won't be much to add as it already loads the scenes additively, and the primary task would be to remove the render texture aspect of it.

https://naninovel.com/guide/custom-acto ... mentations

Elringus
admin
Posts: 538
Joined: 11 May 2020 18:03

Re: Issue with loading scenes from saves

Post by Elringus »

A bit on the side note: I'd strongly recommend against attempting to build custom gameplay (eg, point and click adventures) on top of Naninovel, as its not designed for that. Instead, build the gameplay outside of Naninovel (including all the interaction, state, scenes, etc) and either switch to novel mode or additively show Naninovel when you need dialogues/narrative elements. Both scenarios are described here: https://naninovel.com/guide/integration-options

ZeRAWDOG
Posts: 3
Joined: 01 Oct 2022 04:09

Re: Issue with loading scenes from saves

Post by ZeRAWDOG »

So we built the gameplay elements in normal scene environments, so we weren't just directly doing it in Nani but rather objects within the environment when clicked would go to various labels. Genuinely it was working fine, but the scene loading issue was the main problem. May have come up with a specific solution for this issue but have to make sure performance is okay. Here it is:

void Update()
{
DontDestroyOnLoad(this.gameObject);
if (Engine.GetService<CustomVariableManager>().GetVariableValue("activeScene") != SceneManager.GetActiveScene().name)
{
SceneManager.LoadScene(Engine.GetService<CustomVariableManager>().GetVariableValue("activeScene"));
}
}

The jist of it is pulling the scene variable that we created when the game loads a save. It'll cause an error at least once until the save properly loads, then the update will fix it. We've used integration for a lot of the game, the main issue was simply not keeping the scenes remembered, but with this I think we have resolved the problem. I will update assuming it works as intended!

PS: Def appreciate the quick support!

Post Reply