Jump to content

Are part modules started before the scenario modules?


Recommended Posts

Hi everyone,

I'm having a problem with scenario modules. I have one that contains some settings and other amenities, so that my PartModules can access them.

However, I need to load these values during OnStart(), and it appears that when I try to do that the ScenarioModule hasn't been instantiated yet.

And yes, I did remember to add the scenario to the game before I tried to use it. Does anybody know more about this?

Link to comment
Share on other sites

The other thing to look at is the Awake() method.

From the unity documentation, Awake() runs when the assembly is loaded, Start() runs when the scene is ready to run.

As I understand it, Start() is effectively the first Update() frame where-as Awake() runs as soon as that class is initialized.

Note however that KSP does stuff behind the scenes in Awake and I'm not sure it is available all the time. (So as always, testing required.)

D.

Link to comment
Share on other sites

Would you mind if I asked you for an example?

Well, the most common example would probably be doing something with the R&D instance. I found that trying to access it directly in my own Start leads to problems (at least in flight it does), so I work along these lines instead:

[KSPAddon(KSPAddon.Startup.Flight, false)]
public class RnDAccessor : MonoBehaviour
{
IEnumerator Start()
{
while (ResearchAndDevelopment.Instance == null)
yield return 0;

// now R&D is ready
}
}

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