Jump to content

Scenario getting reset between, with no chance to reload.


Recommended Posts

So I seem to have run into a seemingly insurmountable problem - at least with my own knowledge of things.

I have a scenario which is configured to be active in multiple scenes. When it loads the first time, KSP properly calls the OnLoad giving my scenario the chance to load in the scenario data from the save file. But when I change scenes, it appears that KSP is completely dumping the entire scenario and then recreating it, but this time it is NOT calling OnLoad so I lose all my data without the ability to reload it :(

Very specifically it is first loading in the Editor scene, then when you switch to the Flight scene it is being re-created, but no OnLoad is called.

Anyone have any thoughts?

Link to comment
Share on other sites

My first guess would be, you are modifying a clone and not a reference!

so all changes are not in the life data but in a "dead" copy of it..

I would check the exact way you gather the data - there might be the problem..

Edit: I can't remember all the quirks of scenariomodule right now - it's been a while since I had this project open.. however..

here you will find a working system - maybe it helps you as a reference..

https://github.com/philotical/ResourceRecovery/tree/master/ResourceRecovery/DEV/version-0.1.11

(keep in mind, when I wrote this, I was new to the matter - so it might not be the "standard" way but it works)

hth

Edited by philotical
Link to comment
Share on other sites

Can you post a code example? I am doing exactly this and OnLoad is working as expected for me (running in both scenes).

Note that there can be timing issues, the scenario OnLoad does not always seem to run on scene start, but a few frames later.

D.

Link to comment
Share on other sites

I have a scenario which is configured to be active in multiple scenes. When it loads the first time, KSP properly calls the OnLoad giving my scenario the chance to load in the scenario data from the save file. But when I change scenes, it appears that KSP is completely dumping the entire scenario and then recreating it, but this time it is NOT calling OnLoad so I lose all my data without the ability to reload it

The most common mistake is treating ScenarioModules like KSPAddons. Don't put the KSPAddon flag on them. In the latest update, a new attribute was added to make creating ScenarioModules as easy as KSPAddons:

[KSPScenario(ScenarioCreationOptions.AddToNewCareerGames |
ScenarioCreationOptions.AddToExistingCareerGames |
ScenarioCreationOptions.AddToNewScienceSandboxGames |
ScenarioCreationOptions.AddToExistingScienceSandboxGames,

GameScenes.FLIGHT, GameScenes.EDITOR, GameScenes.SPH /* etc */)]
class MyOwnScenarioModule : ScenarioModule
{
public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);
}
public override void OnSave(ConfigNode node)
{
base.OnSave(node);
}
}

There's one little quirk to know about. You may need to make a normal transition from main menu to space center once to get KSP to add the scenario. After it's been added to the persistent file scenarios, you can go back to using scene skipping code

Link to comment
Share on other sites

Hey guys thanks for all the replies. Been a busy week at work so I will hunker down and look again at this over the weekend. I may need to strip my code down to basics and see what is going on. I could have sworn this *was* working when I did some initial R&D and now that i'm in the middle of my plugin, it isn't working.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...