Jump to content

[WIP] TMS Orbital Mechanics - Stargate Mod : Questions problems and development woes. ;-)


Recommended Posts

Hi all,

As my other thread evolved into what this thread was always meant to be (eventually), I figured I'd just jump right in and make my Mod Development thread.

I will have a lot of questions as I am still getting my head around how c# and the api works.

I have created a Git repository for the Mod as it currently is (or rather isn't, nothing quite works yet), but it will make things easier than me pasting code all the time :)

The readme has some basic information about the mod and what I'm looking to achieve, the readme itself is still a work in progress so may have some bits missing. :)

https://github.com/TheMightySpud/TMS_Orbital_Mechanics

This is just the introductory post, I'll be adding more and having breakdowns/tantrums in other posts further down the line when things go horribly wrong :)

So, on with the show as they say.

TheMightySpud

Link to comment
Share on other sites

Hi all,

So, problem number one on my 'to do' list.

Getting a single gate to spawn anywhere.

Using this code

https://github.com/TheMightySpud/TMS_Orbital_Mechanics/blob/master/Source/CreateGates.cs

which is derived from this code......

https://github.com/Starwaster/Ioncross-Crew-Support/blob/master/Source/IoncrossCrewSupport/Contracts/Templates/IonContractResupply.cs

 Which was so graciously offered up by @Starwaster

I receive this error when trying to spawn the Gate either from entering the Space Center, or entering 'flight'

Part_Error_001.jpg

Based on the outputs from the Log, the code is finding all the necessary information from the config file, which is great.  Originally I thought the problem was something to do with the following line.

https://github.com/TheMightySpud/TMS_Orbital_Mechanics/blob/master/Source/CreateGates.cs#L102-L106

But the Debug lines that follow it print the information asked for to the Log, so I know that there's information in there.  However it doesn't seem to be getting added to the vessel at this point like it should....

https://github.com/TheMightySpud/TMS_Orbital_Mechanics/blob/master/Source/CreateGates.cs#L123-L129

The only thing I can think of is that I'm missing something important from the original code, but I honestly can't see what, and I spent most of yesterday going through it line by line several times to try and find something that I missed.

I'm hoping that someone with a fresh pair of eyes can see where I'm going wrong and point me in the right direction. :)

Thanks

TheMightySpud

Link to comment
Share on other sites

Well the code I used is quite a few KSP versions old so I'm wondering if anything changed with ProtoVessel.CreateVesselNode()?

Have you tried searching the log to see if that function is throwing any exceptions?

If that function hasn't changed significantly then it should be working. Where are you getting the actual vessel list being used? I was using nodes created from actual *.craft files for convenience. It would not work as is with the types of VESSEL nodes that you find in save files. There is a way of making that work with different code that calls  different functions, but this method required something from inside craft files.

So, assuming that you ARE using the right format for your VESSELs, then the next thing you want to look at is each part that is going in. So you'll want to parse each PART in the node and seeing what that part is. Maybe something weird is going on there.

Link to comment
Share on other sites

Thanks for the reply once again :)

In the log I'm getting no exceptions whatsoever, just that little popup window when it tries to load the .craft

Format wise, I'm using a craft file saved from the editor with the edits made (adding STARGATE { VESSEL {  at the beginning and } } at the end.  (I can't see any other differences in the cfg you provided)

So at the moment, it seems that everything is working as it should up to the point where it actually adds the contents of the Part nodes to the actual vessel.  The 'stargateParts' list is populated as demonstrated by the Debug.Log lines (the expected information appears in the Log.

I am beginning to think that there has been some sort of change in the API between versions.

I get the same error no matter what parts I use to create a craft file (I tried a few different single part ships, just to see if it was something I was doing in my gate Part).  I'll try running through the part(s) I have attached to a ship and see what pops up.

Failing that, I'll have a closer look at the CreateVesselNode() and see if I can figure something out.

Thanks

TheMightySpud

Link to comment
Share on other sites

@TheMightySpud

I tested the code in KSP and found a few issues with it. I think some of them stemmed from a Github mishap that resulted in bad files being committed. One of those might have been the vessel config itself, which had VESSEL data lifted right out of a craft file. That does not work with ProtoVessel.CreateVesselNode()! I searched around my drive and found another version of the fleet file that actually works. From the looks of it, I lifted it out of a save file and now that I think about it, I actually had to launch a station of the type that was being put into orbit and do things like extend solar panels and generally make sure it was in the condition I wanted it to be encountered in orbit in.

Another issue with the code is that although it does work as written, stationFleet is not persistent and is only generated one time, so you need to make sure that in your code the fleet list is always initialized prior to trying to read from it. A simple 'fleet.count > 0' check is a good idea followed by reloading the list if it failed the check. (in my testing, I was having to generate the contract using the debug menu which sometimes resulted in the fleet data being blank if I didn't immediately go to mission control and accept the contract)

Other caveats to watch out for: Because of what I said earlier about getting the vessel node from a save file, make sure that it is empty of crew, otherwise it might try to grab existing crew who are on other missions. (Jeb suddenly got teleported to the new station. Apparently Kerbals have transporter technology and nobody told me :P ). Then if the vessel REQUIRES a crew, randomly generate some prior to calling ProtoVessel.CreateVesselNode()

There is a way to do it with craft file format instead but I don't remember what it was....

Edited by Starwaster
spelling errorz
Link to comment
Share on other sites

BTW, I replaced the fleet file with a new one that works so that you can see what it should look like. (again, this came out of a save file, so a bit of work)

https://github.com/Starwaster/Ioncross-Crew-Support/blob/master/KerbalInstallFolder/GameData/IoncrossCrewSupport/Contracts/Stations/station.type2.cfg

Link to comment
Share on other sites

Thanks :)

So now on to the next problem. lol.

I've got the gate appearing where I want it to (based on where I put it in a save file).

It places fine, but as soon as I go to the launch pad, KSP goes nuts. lol.

https://github.com/TheMightySpud/TMS_Orbital_Mechanics/blob/master/Source/CreateGates.cs#L151-L168

This is my positioning code, which works perfectly as far as I can tell.  In the log, this all happens a long time before it goes mental.  Spawning into orbit is also fine and dandy.

This is my log, I'm not really sure what's going on if honest, if I had to guess, there's some problem with the collision detection, but I'm not sure, and have no idea how to fix it if it is.  In the game the Stargate is sitting on the ground quite nicely, but fps drops to almost nothing as the exception is kicked back on every frame, even after the physics have eventually kicked in. :-/

 

Quote

[WRN 22:44:00.151] [HighLogic]: =========================== Scene Change : From EDITOR to FLIGHT (Async) =====================
[WRN 22:44:01.505] ApplicationLauncher already exist, destroying this instance
[LOG 22:44:01.511] AddonLoader: Instantiating addon 'NavWaypoint' from assembly 'KSP'
[LOG 22:44:01.515] AddonLoader: Instantiating addon 'VesselMove' from assembly 'VesselMover'
[LOG 22:44:01.543] ------------------- initializing flight mode... ------------------
[LOG 22:44:01.550] Loading ship from file: U:/Users/TheMightySpud/Kerbal Mod Builds/VisualStudioProjects/KERBAL MODS/Kerbal Space Program/KSP_Data/../saves/stargate1/Ships/VAB/Auto-Saved Ship.craft
[WRN 22:44:01.576] [Part]: PartModule TransferDialogSpawner at mk1pod, index 7: index exceeds module count as defined in cfg.
Looking for TransferDialogSpawner in other indices...
[WRN 22:44:01.578] ...no TransferDialogSpawner module found on part definition. Skipping...
[LOG 22:44:01.580] Untitled Space Craft loaded!
[LOG 22:44:05.999] putting ship to ground: 14.66247
[LOG 22:44:06.003] [Untitled Space Craft]: Ready to Launch - waiting to start physics...
[LOG 22:44:06.009] Crewmember Jebediah Kerman assigned to Mk1 Command Pod, seat # 0 (crew seat index: 0)
[LOG 22:44:06.011] [FLIGHT GLOBALS]: Switching To Vessel Untitled Space Craft ---------------------- 
[LOG 22:44:06.013] setting new dominant body: Kerbin
FlightGlobals.mainBody: Kerbin
[LOG 22:44:06.015] Reference Frame: Rotating
[LOG 22:44:06.026] stage manager resuming...
[LOG 22:44:06.027] Vessel assembly complete!
[LOG 22:44:06.028] stage manager starting...
[LOG 22:44:06.029] all systems started
[LOG 22:44:06.071] Reloaded override drag cube for zeroed cube root part mk1pod on vessel Untitled Space Craft
[WRN 22:44:06.115] HighlightingSystem : Multiple Highlighter components on a single GameObject is not allowed! Highlighter has been disabled on a GameObject with name 'model'.
[EXC 22:44:06.121] ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
    System.Collections.Generic.List`1[Part].get_Item (Int32 index)
    AttachNodeSnapshot.findAttachedPart (.Vessel vessel)
    ProtoPartSnapshot.Init (.Vessel vesselRef)
    ProtoVessel.LoadObjects ()
    Vessel.Load ()
    Vessel.Update ()
[WRN 22:44:06.166] HighlightingSystem : Multiple Highlighter components on a single GameObject is not allowed! Highlighter has been disabled on a GameObject with name 'model'.
[LOG 22:44:06.170] [Kerbin Stargate]: landed - waiting for ground contact to resume physics...
[EXC 22:44:06.172] NullReferenceException: Object reference not set to an instance of an object
    Part.ModulesOnStart ()
    Part+.MoveNext ()
[LOG 22:44:06.173] Reloaded override drag cube for zeroed cube root part TMS.Stargate.V001 (Kerbin Stargate) on vessel Kerbin Stargate
[LOG 22:44:06.175] Reloaded override drag cube for zeroed cube root part TMS.Stargate.V001 (Kerbin Stargate) on vessel Kerbin Stargate
[LOG 22:44:06.185] [ScenarioDestructibles]: Loading... 0 objects registered
[LOG 22:44:06.188] Loading Depletion Nodes
[LOG 22:44:06.190] DepNodeCount:  0
[LOG 22:44:06.191] Loading Biome Nodes
[LOG 22:44:06.193] BiomeNodeCount:  0
[LOG 22:44:06.194] Loading Planet Nodes
[LOG 22:44:06.196] PlanetNodeCount:  0
[LOG 22:44:08.512] [AsteroidSpawner]: No new objects this time. (Odds are 1:2)
[LOG 22:44:08.539] [FlightIntegrator]: Vessel Untitled Space Craft has been unloaded 1.79769313486232E+308, applying analytic temperature 314.967301616924
[LOG 22:44:08.542] [FlightIntegrator]: Vessel Kerbin Stargate has been unloaded 1.79769313486232E+308, applying analytic temperature 314.606754530242
[LOG 22:44:08.554] [Progress Node Reached]: RecordsAltitude
[LOG 22:44:08.556] [Progress Node Reached]: RecordsSpeed
[LOG 22:44:08.558] [Progress Node Reached]: RecordsDistance
[EXC 22:44:08.583] NullReferenceException: Object reference not set to an instance of an object
    Part.OnTriggerStay (UnityEngine.Collider other)
[EXC 22:44:08.584] NullReferenceException: Object reference not set to an instance of an object
    Part.OnTriggerStay (UnityEngine.Collider other)
[EXC 22:44:08.585] NullReferenceException: Object reference not set to an instance of an object
    Part.OnTriggerStay (UnityEngine.Collider other)
[EXC 22:44:08.586] NullReferenceException: Object reference not set to an instance of an object
    Part.OnTriggerStay (UnityEngine.Collider other)
[EXC 22:44:08.587] NullReferenceException: Object reference not set to an instance of an object
    Part.OnTriggerStay (UnityEngine.Collider other)
[EXC 22:44:08.589] NullReferenceException: Object reference not set to an instance of an object
    Part.OnTriggerStay (UnityEngine.Collider other)
[EXC 22:44:08.590] NullReferenceException: Object reference not set to an instance of an object
    Part.OnTriggerStay (UnityEngine.Collider other)

As you can see there are a couple of other errors in there too, which I don't get when spawning in orbit.  So I would assume there's something wrong with my positioning somewhere.

Thanks

TheMightySpud

Link to comment
Share on other sites

Ooooooh, an update.

Okay so I figured that the errors above I were definitely something to do with my collisions.  However, I have no idea what.

But I took a chunk off my Stargate model, and replaced the mesh collider with a box collider and tried placing that instead.  I still get the errors, but I'm back up to a manageable frame rate so I can carry on with other things while I try and figure out what's going on with that.

So I figured I'd show a pic.  Modelling is done on the gate, haven't started on the texturing yet though.  I may get shouted at for this one, but the Tri count as it stands is at 25,740.  Which is a little high, and I may be able to squeeze it down a bit.  But as this is one part, I figured I could get away with it for the time being.

Soooo, obviously because there are no textures, not really a great deal to see, but you get the idea. :)

Stargate_001.png

 

If anyone has any insight into the errors, I would be most appreciative :)

Thanks

TheMightySpud

Link to comment
Share on other sites

Did you have a single collision mesh or multiple convex colliders? And from the log file it appears the collider throwing the errors is a trigger mesh? Maybe disable the trigger mesh until the part sits in game OK - then add it back in - just to narrow down the source of errors.

Link to comment
Share on other sites

On my previous version of the gate model there were a bunch of convex mesh colliders, but on this version, just to test it has a single box collider, which is why I think I'm getting far better frame rates even though I'm still getting the errors (only throwing the exception for one collider instead of a bunch).

The part that's confusing me is that in the log, there is a line that's saying it can't find an object called 'DestructionCollider' it's looking for it in the KPS file structure, but it's not there so obviously it won't be able to find it.  So I started to wonder whether it was something I was doing in Unity when compiling the model.  But then I thought that can't be it because I can use the part in the editors and get it to the launch pad/runway and it works fine.

I'll try the trigger mesh thing once I figure out what that is lol.

Thanks for the insight :)

TheMightySpud

Link to comment
Share on other sites

OK - wasn't sure if you were aware of the convex requirement so tossed it out just in case. Making a guess here but I know Unity has trigger colliders and that your plugin could use to detect an object going through the gate. This along with what you've said and the log dump above makes me think the plugin is looking for a collider named "DestructionCollider" that would have the "Is Trigger" check box checked (just below the "Convex" check box in Unity) and probably have its layer set to "Part Triggers" ( also in Unity). Then when an object entered this collider it would trigger a callback to remove the vessel and place it somewhere else. You might search the code for "DestructionCollider" - and if found see if it's linked to a callback. (remember - this is just a guess - I may be leading you completely astray).

Link to comment
Share on other sites

Okay then,

I've figured out that it's not actually anything to do with the Collision (well not in the way I thought anyway).  The Destruction Collider error is related to the space center 'scene' and appears all the time, mod or no mod.

I have found something very odd going on though which I believe is the culprit, but not really sure how to fix it.

Everything is all dandy and happy until I go to the launchpad or the runway.

If I remove the bits and pieces of code that moves the stargate after it's spawned, everything works great, except it isn't in the right place.

after a quick look and compare of the savegames however I noticed something odd.  The Stargate 'vessel' is made up of a single part.  I've looked at the savegame file at every step of the way (space center -> tracking station -> space center - > VAB or SPH -> Launch Pad or Runway.

Everytime I've gone through, it's all good until I go to the launch pad or runway, at which point after the autosave I look at the save game again, and suddenly my 'Vessel' has two identical parts.

Has anyone come across this before, or know why it's happening?  It's so very very very weird, I really don't get it.

Thanks

TheMightySpud

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