Jump to content

NullReferenceException Having a lot of trouble here


Recommended Posts

Even with verbose debug on, the console doesn't tell me enough to figure this out, so I'm having a tough time here.

Would really appreciate some help:


void Start()
{
GameEvents.onLaunch.Add(BuildShip);
}

public void BuildShip(EventReport e)
{
AvailablePart ap = PartLoader.getPartInfoByName ("cupola");
UnityEngine.Object obj = UnityEngine.Object.Instantiate(ap.partPrefab);
Part newPart = (Part)obj;

newPart.gameObject.name = "cupola";
newPart.partInfo = ap;

ShipConstruct newShip = new ShipConstruct("hello world", "hello world2", newPart);
ShipConstruction.PutShipToGround(newShip, this.part.transform);
ShipConstruction.AssembleForLaunch(newShip, "Kerbin", HighLogic.CurrentGame.flagURL, HighLogic.CurrentGame, new VesselCrewManifest());
}

Running this gives me this error code at launch:


[Exception]: NullReferenceException: Object reference not set to an instance of an object
Part.InitializeModules ()
Vessel.Initialize (Boolean fromShipAssembly)
ShipConstruction.AssembleForLaunch (.ShipConstruct ship, System.String landedAt, System.String flagURL, .Game sceneState, .VesselCrewManifest crewManifest)

The error disappears when I remove ShipConstruction.AssembleForLaunch, but no ship appears. I printed all my instanced object, so I know everything I've meant to instance so far has been instanced.

Link to comment
Share on other sites

The error disappears when I remove ShipConstruction.AssembleForLaunch

Then it has something to do with that function call, likely. I'd check on HighLogic.CurrentGame.flagURL and HighLogic.CurrentGame and make sure neither of those is returning null, and make sure that HighLogic itself isn't null. Maybe try HighLogic.fetch.CurrentGame? Not sure if HighLogic has a fetch...

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