Jump to content

Not seeing sub-nodes in ConfigNode


Recommended Posts

I have a part config that looks like this:

// ...
MODULE
{
name = ODFC
MODE
{
LiquidFuel = 0.01
IntakeAir = 0.15
MaxEU = 100
}
MODE
{
LiquidFuel = 0.09
Oxidizer = 0.11
MaxEU = 100
}
//...

I'm trying to read the various MODE sub-nodes I have in my PartModule. However, when I look at it in my code like so:

		ConfigNode pcn = null;

public void dumpnode() {
if(pcn.HasNode("MODE")) {
// code here never reached
}
else
print("No MODEs found.");
}

public override void OnLoad(ConfigNode cn) {
if(pcn == null)
pcn = cn;
}

public override void OnStart(PartModule.StartState state) {
dumpnode();

if(state == StartState.Editor)
return;

this.part.force_activate();
}

I never see anything printed except "No MODEs found." Puzzled, I even tried recursively dumping every single name/value pair from the ConfigNode handed to me in OnLoad(), and while I could see the "name = ODFC" pair, along with what appeared to be a few tweakable values, I never saw anything contained within the MODE sub-nodes. So, any idea about what I'm doing wrong? I feel like I've missed something fundamental, but in various examples I've looked at, they don't do anything different that I can see.

Link to comment
Share on other sites

Beause you're running this code in OnStart, which only runs once you get to the editor, and OnLoad will run in the loading scene. You'Re switching scenes, and PartModule, which is a MonoBehaviour, unloads private objects. Like your config. Making it public should probably fix that.

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...