Jump to content

part.missionID and vessel.rootPart do not always exist?


Recommended Posts

Alright, I'm stumped by an error I am getting.

I am generating a nullref error that makes no sense to me.


public static string SaveGroupNames(Part p, string str)
{
if (p.missionID == FlightGlobals.ActiveVessel.rootPart.missionID)
{
<snip rest of code>

GitHub with full code.

Sometimes, this if statement generates a nullref error

System.NullReferenceException: Object reference not set to an instance of an object

Through logging I have narrowed it down to this line exactly.

Now, because the method starts executing, I know Part p is a valid part. So either p.missionID is null, or FlightGlobals.ActiveVessel.rootPart.missionID is null. The example generating this still has an active vessel so I know there is a vessel with parts present.

Based on my testing, all parts in a vessel are assigned the same .missionID when a vessel is created at the launchpad. (I'm not sure what happens when a vessel that spawns as one splits in two, but the missionID's staying the same would not cause this error.)

I also saw that as long as a vessel still has a single part left, the vessel will have a .rootPart for me to reference.

However, somewhere my train of logic is getting messed up to allow this nullref error in, can anyone offer any suggestions on what I've done wrong?

D.

Link to comment
Share on other sites

At what point are you getting null-refs? I've had some odd issues with parts when swapping between flight and editor, as, if I recall correctly, a lot of the vessel stuff is null in the editor.

Long shot, I know!

Link to comment
Share on other sites

This was in flight.

FlightGlobals does not exist in the editor, rather to find the root part there is EditorLogic.fetch.startPod.

This was one of the earlier errors in my fight with partModules over the past bit, I suspect this is a cascade error from that somehow.

D.

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