Jump to content

TheMightySpud

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by TheMightySpud

  1. 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
  2. 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
  3. 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. If anyone has any insight into the errors, I would be most appreciative Thanks TheMightySpud
  4. 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. :-/ 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
  5. YES!!!!!!! You sir, are an absolute Prince. I now have an orbiting Stargate on startup :-D Me so happy. Now to dissect a save file for positional data. :-D *giddy as a schoolgirl* lol. Seriously though @Starwaster, thank you so much TheMightySpud
  6. After a very quick poke around with google, I found this (DarkMultiplayer code) https://github.com/godarklight/DarkMultiPlayer/blob/master/Client/ScenarioWorker.cs#L241-L266 Which seems to do pretty much the same thing (with a few differences obviously). I'll have a play with that and see what I can come up with TheMightySpud
  7. 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
  8. 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' 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
  9. 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
  10. Well, I got around to setting myself a git repository so it should be a lot easier to read the stuff I'm going to be asking about Also added the beginnings of a readme with most of what I'm trying to accomplish, so it may give everyone a better idea. I'm going to end this thread, and create a new one specifically for the mod as this was supposed to be general questions and it has evolved somewhat. TheMightySpud
  11. Thanks again for that After playing around for a bit more adding in those few lines, it turns out it's doing what it supposed to (It's finding the Node(s) called PART, but the problem is It doesn't seem to be adding any of the info inside the PART node(s) into the ship, which is why I'm getting the 'Craft File not loaded because of missing part ..........' Error when I start up KSP. I'll have a bit more of a play to see if I can figure it all out TheMightySpud
  12. My apologies, it's getting late and I overlooked including the log. Anyway, this is what happened in the log. As you can see the stargateList (Gates in list) has 1 entry, which it should have. the stargateList[0].name comes out as 'VESSEL' (Stargate NameVESSEL) which if I'm look at this correctly, it should really be the ship name as defined in the cfg file (which is a slightly modified craft file), and then when I try to grab the PART in the line I mentioned in my previous post, I get a stargateParts[0] value of PART (Part NamePART), which should (I believe) be the actual part assigned to the ship. All of this is a lot of guesswork tbh but I'm learning, and picking up how stuff works. As for Github, I don't have one as yet, but I plan to sort it out this weekend sometime. Really appreciate the help TheMightySpud
  13. Hooooookay, Spent a couple of hours trying to figure this out and have gotten nowhere. :-/ // ------------------------------------------------------------------------------ // <autogenerated> // This code was generated by a tool. // Mono Runtime Version: 4.0.30319.1 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </autogenerated> // ------------------------------------------------------------------------------ using KSP; using UnityEngine; using Contracts; using Contracts.Parameters; using System; using System.Collections.Generic; using System.Linq; namespace TMS_Stargate { public class CreateGates : MonoBehaviour { //Define a load of lists and variables private List<ConfigNode> stargateList = new List<ConfigNode>(); private CelestialBody gateBody = null; private string _planet; public string stargateName = "Unnamed Stargate"; public List<ConfigNode> GetProtoGate() { //Defines our list of Stargates Debug.Log("TMS ORBITAL MECHANICS - Defining our Gate List"); List<ConfigNode> Stargates = new List<ConfigNode>(); Debug.Log("TMS ORBITAL MECHANICS - Defined our Gate List"); //Loops through all the configs to find any starting with a Node called STARGATE Debug.Log("TMS ORBITAL MECHANICS - About to Start our first foreach Loop"); foreach (ConfigNode gates in GameDatabase.Instance.GetConfigNodes("STARGATE")) { Debug.Log("TMS ORBITAL MECHANICS - Gates in list = " + Stargates.Count); Debug.Log("TMS ORBITAL MECHANICS - found STARGATE node"); Debug.Log("TMS ORBITAL MECHANICS - About to Start our Second ForEach loop"); //Finds all the VESSEL Nodes in our Configs foreach (ConfigNode stargate_candidate in gates.GetNodes("VESSEL")) { //Adds any relevant items from the Configs to our Stargate List Debug.Log("TMS ORBITAL MECHANICS - found VESSEL node"); Debug.Log("TMS ORBITAL MECHANICS - Adding to candidate List"); Stargates.Add(stargate_candidate); Debug.Log("TMS ORBITAL MECHANICS - Gates in list = " + Stargates.Count); } } //Sends the completed list back to the main bit Debug.Log("TMS ORBITAL MECHANICS - Returning Info"); return Stargates; } public void BuildGate(string planet) { //Defines which planet/moon we are referencing this._planet = planet; Debug.Log("The Commencement has Beginulated"); foreach (CelestialBody targetBody in FlightGlobals.Bodies) { Debug.Log("TMS ORBITAL MECHANICS - Found Body " + targetBody); if (targetBody.name == _planet) gateBody = targetBody; } Debug.Log("Locked on to " + gateBody); Debug.Log("TMS ORBITAL MECHANICS - Trying to Spawn a Gate"); //Sends a request to 'GetProtoGate' to grab info we can use. Debug.Log("TMS ORBITAL MECHANICS - Going to GetProtoGate"); stargateList = GetProtoGate(); Debug.Log("TMS ORBITAL MECHANICS - Coming back from GetProtoGate"); //Checks to make sure we're getting something back if (stargateList.Count <= 0) { Debug.Log("TMS ORBITAL MECHANICS - about to return false (empty fleet nodes; unable to spawn)"); //return false; } //Give our Stargate a name stargateName = gateBody.bodyName + " Stargate"; Debug.Log("TMS ORBITAL MECHANICS - Stargate Name = " + stargateName); //Defines out unique flightID Debug.Log("TMS ORBITAL MECHANICS - assign Flight ID"); uint uniqueFlightID = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState); Debug.Log("TMS ORBITAL MECHANICS - Stargate Name" + stargateList[0].name); //Tries to get all the parts from our loaded vessel config file Debug.Log("TMS ORBITAL MECHANICS - Get Parts"); ConfigNode[] stargateParts = stargateList[0].GetNodes("PART"); Debug.Log("TMS ORBITAL MECHANICS - Part Name" + stargateParts[0].name); //Define our orbit details (Needs heavy editing to put our gates exactly where we want them. Ideally getting info from TMS_Stargate.cs) Debug.Log("TMS ORBITAL MECHANICS - Defining Orbit Details"); double lowOrbit = Math.Max(gateBody.Radius + gateBody.Radius * 0.15, gateBody.Radius + (double)gateBody.atmosphereDepth * 2.0); double highOrbit = Math.Max(gateBody.Radius + gateBody.Radius * 0.2, gateBody.Radius + (double)gateBody.atmosphereDepth * 2.3); Debug.Log("TMS ORBITAL MECHANICS - Defining Parameters config node"); //Define our parameters node (not actually sure what this does if honest) ConfigNode[] parameters = new ConfigNode[] { ProtoVessel.CreateDiscoveryNode(DiscoveryLevels.Unowned, UntrackedObjectClass.A, 50000 * 2.0, 50000 * 2.0) }; //Assign our orbit details to our actual orbit Debug.Log("TMS ORBITAL MECHANICS - Creating Orbit details"); Orbit orbit = Orbit.CreateRandomOrbitAround(this.gateBody, lowOrbit, highOrbit); //Define and add our details to the ProtoVessel Debug.Log("TMS ORBITAL MECHANICS - Adding all info to the ProtoVesselNode"); ConfigNode protoVesselNode = ProtoVessel.CreateVesselNode(stargateName, VesselType.Station, orbit, 0, stargateParts, parameters ); //Add our ProtoVessel to the game Debug.Log("TMS ORBITAL MECHANICS - Adding our Gate to the game(I think)"); ProtoVessel protoVessel = HighLogic.CurrentGame.AddVessel(protoVesselNode); } } } Here's what I've got (Yes, it's a Stargate Mod, don't judge me. lol.) All credit to @Starwaster for the code, making more headway with this than I have any other. I've got the thing to read the file and attempt loading, but there's a line that's causing a bit of a problem. This little nugget seems to refuse to read the parts of the loaded file. ConfigNode[] stargateParts = stargateList[0].GetNodes("PART"); In Starwasters original code this was set to look for a random value based on how many items were in the 'stargateList' however as this will only ever return a single item, I've set it to 0. But I can't see what it won't get the parts. :-/ Thanks. TheMightySpud
  14. AH HAAAAA!!!! Thank you so so so so so so so much. Got it to read everything, now I'm getting a new error. lol. This one is an 'in game' error saying that it can't load the vessel because of a missing part, but it doesn't say which part, it's just blank.....lol. Well, time to go and mess about with stuff Thanks again TheMightySpud
  15. The cfg is currently in 'GameData/MyMod/PluginData/' So very confused as to why it's not working. I'll have a look for the debug mode thingy you mentioned, Thanks for that Thanks TheMightySpud
  16. Thanks for the pointers @Starwaster, it's really been helpful. I've edited down the code quite substantially to the best of my knowledge, and logically it all seems fine. However there is a problem which I can't seem to figure out. I've narrowed down where the problem is, and it's definitely something to do with finding and parsing the config. In this part of the code....... public List<ConfigNode> GetProtoModule() { Debug.Log("TMS ORBITAL MECHANICS - Defining our Module List"); List<ConfigNode> Modules = new List<ConfigNode>(); Debug.Log("TMS ORBITAL MECHANICS - Defined our Module List"); //Loops through all TMSMODULE001 configNodes in the GameDatabase Debug.Log("TMS ORBITAL MECHANICS - About to Start our first foreach Loop"); foreach (ConfigNode modules in GameDatabase.Instance.GetConfigNodes("TMSMODULE001")) { Debug.Log("TMS ORBITAL MECHANICS - Modules in list = " + Modules.Count); Debug.Log("TMS ORBITAL MECHANICS - found TMSMODULE001 node"); Debug.Log("TMS ORBITAL MECHANICS - About to Start our Second ForEach loop"); foreach (ConfigNode module_candidate in gates.GetNodes("VESSEL")) { Debug.Log("TMS ORBITAL MECHANICS - found VESSEL node"); Debug.Log("TMS ORBITAL MECHANICS - Adding to candidate List"); Modules.Add(module_candidate); Debug.Log("TMS ORBITAL MECHANICS - Modules in list = " + Modules.Count); } } Debug.Log("TMS ORBITAL MECHANICS - Returning Info"); return Modules; } Everything works fine, except that it never finds the node 'TMSMODULE001' So everything else carries on, but as soon as it starts to go through the PART node, it craps out. This is the log of that section so you can see what's happening. As you can see it craps out when trying to get the Parts because there's nothing to get, and I'm a little bit stumped :-/ This is the config file I'm trying to reference. It's just a mk1 pod at the moment for testing purposes, I've tried to match the sample that was provided but I may have missed something. :-/ TMSMODULE001 { VESSEL { ship = Untitled Space Craft version = 1.0.5 description = mk1pod Test Vehicle type = VAB size = 1.268897,1.132535,1.270908 PART { part = mk1pod_4294731242 partName = Part pos = 0,15,0 attPos = 0,0,0 attPos0 = 0,15,0 rot = 0,0,0,1 attRot = 0,0,0,1 attRot0 = 0,0,0,1 mir = 1,1,1 symMethod = Radial istg = 0 dstg = 0 sidx = -1 sqor = -1 sepI = 0 attm = 0 modCost = 0 modMass = 0 modSize = (0.0, 0.0, 0.0) EVENTS { } ACTIONS { } PARTDATA { } MODULE { name = ModuleCommand isEnabled = True controlSrcStatusText = stagingEnabled = True EVENTS { MakeReference { active = True guiActive = True guiActiveUncommand = False guiIcon = Control From Here guiName = Control From Here category = Control From Here guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } RenameVessel { active = True guiActive = True guiActiveUncommand = True guiIcon = Rename Vessel guiName = Rename Vessel category = Rename Vessel guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { } } MODULE { name = ModuleReactionWheel isEnabled = True stateString = Active stagingEnabled = True WheelState = Active EVENTS { OnToggle { active = True guiActive = True guiActiveEditor = True guiActiveUncommand = False guiIcon = Toggle Torque guiName = Toggle Torque category = Toggle Torque guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { Activate { actionGroup = None } Deactivate { actionGroup = None } Toggle { actionGroup = None } } } MODULE { name = ModuleScienceExperiment isEnabled = True Deployed = False Inoperable = False stagingEnabled = True EVENTS { DeployExperiment { active = True guiActive = True guiActiveUncommand = False guiIcon = Deploy guiName = Deploy category = Deploy guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } CollectDataExternalEvent { active = True guiActive = False guiActiveUncommand = False guiIcon = guiName = category = guiActiveUnfocused = True unfocusedRange = 1.5 externalToEVAOnly = True } ReviewDataEvent { active = True guiActive = True guiActiveUncommand = False guiIcon = Review Data guiName = Review Data category = Review Data guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } ResetExperiment { active = True guiActive = True guiActiveUncommand = False guiIcon = Reset guiName = Reset category = Reset guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } DeployExperimentExternal { active = True guiActive = False guiActiveUncommand = False guiIcon = Deploy guiName = Deploy category = Deploy guiActiveUnfocused = True unfocusedRange = 2 externalToEVAOnly = True } ResetExperimentExternal { active = True guiActive = False guiActiveUncommand = False guiIcon = Reset guiName = Reset category = Reset guiActiveUnfocused = True unfocusedRange = 2 externalToEVAOnly = True } CleanUpExperimentExternal { active = True guiActive = False guiActiveUncommand = False guiIcon = Restore guiName = Restore category = Restore guiActiveUnfocused = True unfocusedRange = 2 externalToEVAOnly = True } ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { DeployAction { actionGroup = None } ResetAction { actionGroup = None } } } MODULE { name = ModuleScienceContainer isEnabled = True stagingEnabled = True EVENTS { StoreDataExternalEvent { active = False guiActive = False guiActiveUncommand = False guiIcon = guiName = Store Experiments (0) category = guiActiveUnfocused = True unfocusedRange = 1.3 externalToEVAOnly = True } CollectDataExternalEvent { active = False guiActive = False guiActiveUncommand = False guiIcon = guiName = Take Data (0) category = guiActiveUnfocused = True unfocusedRange = 1.3 externalToEVAOnly = True } ReviewDataEvent { active = False guiActive = True guiActiveUncommand = False guiIcon = Review Data guiName = Review Stored Data (0) category = Review Data guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { } } MODULE { name = FlagDecal isEnabled = True flagDisplayed = True stagingEnabled = True EVENTS { ToggleFlag { active = True guiActive = False guiActiveEditor = True guiActiveUncommand = False guiIcon = Toggle Flag guiName = Toggle Flag category = Toggle Flag guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { } } MODULE { name = ModuleConductionMultiplier isEnabled = True stagingEnabled = True EVENTS { ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { } } MODULE { name = ModuleTripLogger isEnabled = True stagingEnabled = True EVENTS { ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { } Log { flight = 0 } } MODULE { name = TransferDialogSpawner isEnabled = True stagingEnabled = True EVENTS { SpawnDialog { active = True guiActive = True guiActiveUncommand = True guiIcon = Transfer Crew guiName = Transfer Crew category = Transfer Crew guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } ToggleStaging { active = True guiActive = False guiActiveUncommand = False guiIcon = Disable Staging guiName = Disable Staging category = Disable Staging guiActiveUnfocused = False unfocusedRange = 2 externalToEVAOnly = True } } ACTIONS { } } RESOURCE { name = ElectricCharge amount = 50 maxAmount = 50 flowState = True isTweakable = True hideFlow = False isVisible = True flowMode = Both } RESOURCE { name = MonoPropellant amount = 10 maxAmount = 10 flowState = True isTweakable = True hideFlow = False isVisible = True flowMode = Both } } } } From what I can see it's just a matter of wrapping the existing Craft file contents inside TMSMODULE001 { VESSEL { } } tags. But like I say I could have missed something. Thanks TheMightySpud
  17. Hmmm........ So I've been playing around for a while with the code that @Starwaster provided, and I'm pretty sure I'm on the right track........however (yes there's always a however), it would appear as though the config file doesn't get added to the database (I double checked in the Alt+f12 options and it's nowhere to be seen). So I'm a bit stumped. I tried loading the file directly, but I couldn't get my head around how to do that at all. :-/ Anyone have any ideas? Thanks TheMightySpud
  18. Ooooooh...... After a quick glance over I think this is going to be very helpful. From what I can tell it pretty much does exactly what I want to do, all I need to do I think is remove the contracts parts (with a little fiddling obviously :)) and tie it to a specific craft file instead of searching through the database. Thank you so much for that TheMightySpud
  19. Hi all, I really really really really really really (yes, really :-P) Hope someone can see where I'm going wrong on this...... What I'm trying to do is spawn a vessel (loaded from an existing Craft file) at startup, using KSPAddon to trigger the spawning when you enter the space center from the main menu, when I've got it working there will be a check to see if the vessel already exists, but for now I just want to get it to spawn. I've got it triggering the code, but then something weird is happening and it's driving me nuts. Any time after a certain point that I try to do anything with the _newVessel I get an exception and it breaks. The Exception (from the log) is The code (below) is a modified version of KSPSmelter by @TAz00, which in turn is a modified bit of code from KAS. The biggest problem has been converting the code to spawn at a specific point in the 'universe' from spawning based on the position of a Part, so I think I've broken something somewhere. The actual spawn location isn't important at the moment, I'll be translating save game position data to place the object once I have this part working properly. I've been staring/fiddling/kicking this code for almost two days solid so I really do hope someone can help out. Code for creating/spawning the vessel. using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace TMS_Module_001 { /// <summary> /// This class is pretty much built on what KAS uses to pull parts out of containers /// All credit to https://github.com/KospY/KAS /// https://github.com/KospY/KAS/blob/master/LICENSE.md /// </summary> public class VesselSpawner { const string PluginPath = "\\GameData\\TMSOrbitalMechanics\\PluginData\\"; private HideConfigNode _OldVabShip; private string _craftFile = ""; private string vesselName = ""; private Vector3 vesselPosition = new Vector3(0.0f, 0.0f, 0.0f); private CelestialBody bodyKerbin = null; /// <summary> /// /// </summary> /// <param name="_craftFile">Craft file name as it appears in the PluginPath folder</param> /// <param name="_srcPart">Source part to spawn relative to</param> /// <param name="_spawnOffset">Offset spawn from Source part position</param> //public VesselSpawner(string _craftFile, Vector3 _spawnOffset) public VesselSpawner(string _craftFile, string vesselName, Vector3 vesselPosition, CelestialBody bodyKerbin) { //Store paths this._craftFile = _craftFile; this.vesselPosition = vesselPosition; this.vesselName = vesselName; this.bodyKerbin = bodyKerbin; } /// <summary> /// Spawns the vessel /// </summary> public void SpawnVessel() { Debug.Log("SpawnVessel"); //Load craft file ShipConstruct _ship = LoadVessel(this._craftFile); if (_ship != null) { SpawnVessel(this.vesselName, _ship, this.vesselPosition); } else { Debug.Log("Failed to load the vessel"); } } /// <summary> /// Attempt vessel load /// </summary> /// <param name="_craftFile"></param> /// <returns></returns> private ShipConstruct LoadVessel(string _craftFile) { Debug.Log("ConstructVessel"); //Get path to vessel Debug.Log("Loading the craft file"); string BasePath = Environment.CurrentDirectory + PluginPath; string path = BasePath + _craftFile; Debug.Log(path); //Save old ship for later, else player will see it in the VAB _OldVabShip = new HideConfigNode(ShipConstruction.ShipConfig); //Load craft file ShipConstruct _shipConstruct = ShipConstruction.LoadShip(path); //Check load Debug.Log("Checking if its loaded"); if (_shipConstruct == null) { // Restore ShipConstruction ship, otherwise player sees loaded craft in VAB ShipConstruction.ShipConfig = _OldVabShip.GetConfigNode(); return null; //Fail } Debug.Log("Sending it back"); return _shipConstruct; } /// <summary> /// Spawn ship construct /// https://github.com/KospY/KAS/blob/master/Plugin/KAS_Shared.cs /// </summary> /// <param name="_shipConstruct">Shipconstruct to spawn</param> /// <param name="_srcPart">Source part to spawn relative to</param> /// <param name="_spawnOffset">Offset spawn from Source part position</param> private void SpawnVessel(string vesselName, ShipConstruct _shipConstruct, Vector3 _spawnOffset) { Debug.Log("PrivateSpawnVessel"); //Store construct root Part _newConstructRootPart = _shipConstruct.parts[0]; Debug.Log("Doing something with the Root"); //Center rootpart Vector3 offset = _newConstructRootPart.transform.localPosition; _newConstructRootPart.transform.Translate(-offset); Debug.Log("Setting Root position or something"); //Get launch spawn point. GameObject launchPos = new GameObject(); launchPos.transform.position = vesselPosition; //Store our launch / spawn position Transform launchTransform = launchPos.transform; //Kill original object launchPos.DestroyGameObject(); //Set rootpart origin _shipConstruct.Parts[0].localRoot.transform.Translate(launchPos.transform.position, Space.World); //Position float angle; Vector3 axis; //Extract ToAngleAxis data from selected spawning location launchTransform.rotation.ToAngleAxis(out angle, out axis); //TRANSFORM Rotate localRootPart in relation to root _shipConstruct.Parts[0].localRoot.transform.RotateAround(launchTransform.position, axis, angle); //Create vessel object Debug.Log("CreateVesselObject"); Vessel _newVessel = _newConstructRootPart.localRoot.gameObject.AddComponent<Vessel>(); Debug.Log("Adding all the info to the ship"); //Attach vessel information _newVessel.id = Guid.NewGuid(); _newVessel.name = vesselName; //_newVessel.Landed = true; _newVessel.Splashed = false; _newVessel.landedAt = string.Empty; _newVessel.situation = Vessel.Situations.LANDED; _newVessel.vesselType = VesselType.Base; //Init from VAB _newVessel.Initialize(true); //_newVessel.vesselName = _srcPart.vessel.vesselName + " - " + _shipConstruct.shipName; //_newVessel.landedAt = _srcPart.vessel.vesselName; //Store backup ShipConstruction.CreateBackup(_shipConstruct); Debug.Log("MissionIDStuff"); //Set Orbit InitiateOrbit(vesselPosition, _newVessel); //Set Mission info Debug.Log("Set Mission ID"); uint missionId = (uint)Guid.NewGuid().GetHashCode(); //string flagUrl = _srcPart.flagURL; Debug.Log("Set Launch ID"); uint launchId = HighLogic.CurrentGame.launchID++; //Set part mission info for (int i = 0; i < _newVessel.parts.Count; i++) { Debug.Log(_newVessel.parts.Count); Debug.Log("Loop through parts"); Part part = _newVessel.parts[i]; Debug.Log(part.name); part.flightID = ShipConstruction.GetUniqueFlightID(FlightDriver.FlightStateCache.flightState); Debug.Log("Done it Once"); part.launchID = launchId; part.missionID = missionId; } Debug.Log("Finished Mission Stuff"); //Generate staging //Staging.beginFlight(); //_newConstructRootPart.vessel.ResumeStaging(); //Staging.GenerateStagingSequence(_newConstructRootPart.localRoot); //Staging.RecalculateVesselStaging(_newConstructRootPart.vessel); //Set position, again _newVessel.SetPosition(launchTransform.position); _newVessel.SetRotation(launchTransform.rotation); //Get all the parts, does it even matter since we launch from VAB? for (int i = 0; i < _newVessel.parts.Count; i++) { // Solar panels from containers (we dont have no bloody containers here tho) don't work otherwise for (int j = 0; j < _newVessel.parts[i].Modules.Count; j++) { ConfigNode node = new ConfigNode(); node.AddValue("name", _newVessel.parts[i].Modules[j].moduleName); _newVessel.parts[i].LoadModule(node, ref j); } } Debug.Log("ProtoVesselStuff"); //Save Protovessel ProtoVessel _newProto = new ProtoVessel(_newVessel); Debug.Log("Defined ProtoVessel"); if (_newProto == null) { Debug.Log("Nope"); } else { Debug.Log("If Statement if not failed"); //Kill and remove spawned vessel, had some serious problems with spawn position warping/glitching // Debug.Log("_newVessel Die"); _newVessel.Die(); Debug.Log("New Vessel Dead"); Debug.Log(launchPos.transform.position); //Set the protovessels position to the relative one we found, maybe redundant Debug.Log("Move ProtoVessel"); _newProto.position = launchPos.transform.position; //If you check this value, you will see the height change from launch scene to resume scene, extra dafuq float height = _newProto.height; if (FlightDriver.StartupBehaviour == FlightDriver.StartupBehaviours.RESUME_SAVED_FILE || FlightDriver.StartupBehaviour == FlightDriver.StartupBehaviours.RESUME_SAVED_CACHE) { //Odd behaviour with positioning during different flight scenes, workaround awaaaay //_newProto.height = TrueAlt(launchTransform.position, _newProto.height); //} //Load Protovessel Debug.Log("ProtoVessel Load"); _newProto.Load(HighLogic.CurrentGame.flightState); // Restore ShipConstruction ship, otherwise player sees loaded craft in VAB ShipConstruction.ShipConfig = _OldVabShip.GetConfigNode(); } } } /// <summary> /// http://forum.kerbalspaceprogram.com/threads/111116-KSP-Altitude-Calculation-Inquiry /// </summary> /// <returns></returns> //private float TrueAlt(Vector3 _LauncPos, Vessel _srcVessel) //{ // Debug.Log("Altitude Stuff?"); // //Vector3 pos = _srcPart.transform.position; //or this.vessel.GetWorldPos3D() // float ASL = FlightGlobals.getAltitudeAtPos(_LauncPos); // if (_srcVessel.mainBody.pqsController == null) { return ASL; } // float terrainAlt = Convert.ToSingle(_srcVessel.pqsAltitude); // if (_srcVessel.mainBody.ocean && _srcVessel.heightFromTerrain <= 0) { return ASL; } //Checks for oceans // return ASL - terrainAlt; //} /// <summary> /// https://github.com/taniwha-qf/Extraplanetary-Launchpads/blob/master/Source/BuildControl.cs /// https://github.com/taniwha-qf/Extraplanetary-Launchpads/blob/master/License.txt /// </summary> /// <param name="_newVessel"></param> /// <param name="_srcVessel"></param> private void InitiateOrbit(Vector3 vesselPosition, Vessel _newVessel) { Debug.Log("More OrbitStuff"); var mode = OrbitDriver.UpdateMode.UPDATE; _newVessel.orbitDriver.SetOrbitMode(mode); var craftCoM = GetVesselWorldCoM(_newVessel); //var vesselCoM = _newVessel.findWorldCenterOfMass; var uTime = Planetarium.GetUniversalTime(); var vesselCoM = vesselPosition; var offset = (Vector3d.zero + craftCoM - vesselCoM).xzy; _newVessel.orbit.Init(); _newVessel.orbit.StartUT = uTime; _newVessel.orbit.referenceBody = bodyKerbin; //_newVessel.orbit.pos = vesselPosition; //_newVessel.orbit.vel = new Vector3d(0, 0, 0); //_newVessel.angularMomentum = Vector3.zero; //_newVessel.angularVelocity = Vector3.zero; _newVessel.latitude = -1.0f; _newVessel.longitude = 1.0f; _newVessel.heightFromTerrain = 0.0f; //_newVessel.SetRotation(0,0); //_newVessel.altitude = 70.8178020151099; var corb = _newVessel.orbit; corb.UpdateFromStateVectors(corb.pos + offset, _newVessel.orbit.vel, bodyKerbin, uTime); Debug.Log(String.Format("[EL] {0} {1}", "This is Orbit Info", corb.pos)); } public Vector3 GetVesselWorldCoM(Vessel v) { var com = v.findLocalCenterOfMass(); return v.rootPart.partTransform.TransformPoint(com); } } } The trouble starts when I hit the line..... part.flightID = ShipConstruction.GetUniqueFlightID(FlightDriver.FlightStateCache.flightState); Just as an excersize I commented out that line, and then it threw the exception at Debug.Log("_newVessel Die"); _newVessel.Die(); Debug.Log("New Vessel Dead"); leading me to think that it's something to do with the way I've created/modified the vessel. :-/ Code for calling the spawn...... using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace TMS_Module_001 { [KSPAddon(KSPAddon.Startup.SpaceCentre, true)] public class TMS_Stargate : MonoBehaviour { public CelestialBody bodyMun; public CelestialBody bodyKerbin; public void Awake() { string vesselName = "Module 001"; //string celestialBody = "Kerbin"; //CelestialBody celestialBody = new CelestialBody(); foreach (CelestialBody targetBody in FlightGlobals.Bodies) { if (targetBody.name == "Kerbin") bodyKerbin = targetBody; } //string targetBody = celestialBody.name; Vector3 vesselPosition = new Vector3(5f, 0f, 5f); VesselSpawner TMS_Module_001 = new VesselSpawner("TMS_Module_001.craft", vesselName, vesselPosition, bodyKerbin); Debug.Log("Spawn the Ship"); TMS_Module_001.SpawnVessel(); Debug.Log("Ship has Spawned"); } } } So again, I really hope someone can shed some light on this, even if it's a case of pointing me in the right direction of what to look at Thanks TheMightySpud
  20. Wow, Okay, I'll refrain from trying to help from now on.
  21. Thanks @artwhaley, I did see that (I think I've seen pretty much every thread involving spawning vessels. lol.) The problem I'm having with a lot of the threads is how to use the methods etc. that are mentioned. I'm still dissecting the KSPSmelter plugin as it looks like that's the most promising (I am definitely making progress:)). It's just a matter of figuring out what it's doing and how to change it from spawning based on the location of a vessel part and spawning it in world space instead. TheMightySpud
  22. Ah, my bad I forgot to mention that. lol. It seems that most people recommend 4.2.2 because after that version some things were removed from Unity (I think mainly the ability to animate emissive textures, for turning on lights and the like) The Part Tools package (0.23 I think) supports upto a later version but off the top of my head I can't remember which. For most 'compatibility/features' I'd stick with 4.2.2 personally. TheMightySpud
  23. I'm new to this myself, but..... A programming environment for c# (I believe Visual Studio Express is free) If you want to make your own parts, some kind of 3D modelling program (Blender is free, and seems popular around here). Just did a really quick poke around and found this, I don't know how up to date or accurate it is, but it should be a start Sketchup is also a possibility, however I'm not sure if it has UVmapping tools and I think you have to get the pro version to get fbx export capabilities. A copy of the Unity Game Engine (it's free for non-commercial use). The KSP Part Tools addon (From Here), it's linked elsewhere on the forum, but it's a pig to find. Notepad (yep, not kidding ;-)) A read through of this (and always handy to keep closeby for quick reference) And then there's this......umm.....there are gaps, but again, it's a start. And if anything stumps you etc. Just ask questions, people seem to be helpful and pleasant enough And Welcome to the club TheMightySpud
  24. Right then, completely changed my approach. I found a plugin that was a lot easier to 'read' than the others I've seen. Typically I now can't find the thread (The mod is called KSPSmelter) to give proper credit, as soon as I do though I will. The Smelter mod makes use of code modified from Planetary Launch systems (I believe) and the Kerbal Attachment system. I'm making progress on whittling down what I need and modifying it to be a partless mod. But I've hit something of a roadblock with an exception error. (I think I've commented something important out. lol.) This is the vehicle 'Spawner code' using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace TMS_Module_001 { /// <summary> /// This class is pretty much built on what KAS uses to pull parts out of containers /// All credit to https://github.com/KospY/KAS /// https://github.com/KospY/KAS/blob/master/LICENSE.md /// </summary> public class VesselSpawner { const string PluginPath = "\\GameData\\TMSOrbitalMechanics\\PluginData\\"; private HideConfigNode _OldVabShip; private string _craftFile = ""; private string vesselName = ""; private Vector3 vesselPosition = new Vector3(0, 0, 0); //private Part _srcPart = null; /// <summary> /// /// </summary> /// <param name="_craftFile">Craft file name as it appears in the PluginPath folder</param> /// <param name="_srcPart">Source part to spawn relative to</param> /// <param name="_spawnOffset">Offset spawn from Source part position</param> //public VesselSpawner(string _craftFile, Vector3 _spawnOffset) public VesselSpawner(string _craftFile, string vesselName, Vector3 vesselPosition) { //Store paths this._craftFile = _craftFile; //this._srcPart = _srcPart; this.vesselPosition = vesselPosition; this.vesselName = vesselName; //if (this._srcPart == null) // Debug.Log("Relative source part can't be null"); //if ((_craftFile != String.Empty)) // Debug.Log("Source part path can't be null"); } /// <summary> /// Spawns the vessel /// </summary> public void SpawnVessel() { Debug.Log("SpawnVessel"); //Load craft file ShipConstruct _ship = LoadVessel(this._craftFile); if (_ship != null) SpawnVessel(this.vesselName, _ship, this.vesselPosition); else Debug.Log("Failed to load the vessel"); } /// <summary> /// Attempt vessel load /// </summary> /// <param name="_craftFile"></param> /// <returns></returns> private ShipConstruct LoadVessel(string _craftFile) { Debug.Log("ConstructVessel"); //Get path to vessel Debug.Log("Loading the craft file"); string BasePath = Environment.CurrentDirectory + PluginPath; string path = BasePath + _craftFile; Debug.Log(path); //Save old ship for later, else player will see it in the VAB _OldVabShip = new HideConfigNode(ShipConstruction.ShipConfig); //Load craft file ShipConstruct _shipConstruct = ShipConstruction.LoadShip(path); //Check load Debug.Log("Checking if its loaded"); if (_shipConstruct == null) { // Restore ShipConstruction ship, otherwise player sees loaded craft in VAB ShipConstruction.ShipConfig = _OldVabShip.GetConfigNode(); return null; //Fail } Debug.Log("Sending it back"); return _shipConstruct; } /// <summary> /// Spawn ship construct /// https://github.com/KospY/KAS/blob/master/Plugin/KAS_Shared.cs /// </summary> /// <param name="_shipConstruct">Shipconstruct to spawn</param> /// <param name="_srcPart">Source part to spawn relative to</param> /// <param name="_spawnOffset">Offset spawn from Source part position</param> private void SpawnVessel(string vesselName, ShipConstruct _shipConstruct, Vector3 _spawnOffset) { Debug.Log("PrivateSpawnVessel"); //Store construct root Part _newConstructRootPart = _shipConstruct.parts[0]; Debug.Log("Doing something with the Root"); //Center rootpart Vector3 offset = _newConstructRootPart.transform.localPosition; _newConstructRootPart.transform.Translate(-offset); //Get launch spawn point, relative to part //Transform t = _srcPart.transform; //GameObject launchPos = new GameObject(); //launchPos.transform.parent = _srcPart.transform; //launchPos.transform.position = t.position; //launchPos.transform.position += t.TransformDirection(_spawnOffset); //launchPos.transform.rotation = t.rotation; //Store our launch / spawn position //Transform launchTransform = launchPos.transform; //Kill original object //launchPos.DestroyGameObject(); //Set rootpart origin //_shipConstruct.Parts[0].localRoot.transform.Translate(launchPos.transform.position, Space.World); //Position //float angle; //Vector3 axis; //Extract ToAngleAxis data from selected spawning location //launchTransform.rotation.ToAngleAxis(out angle, out axis); //TRANSFORM Rotate localRootPart in relation to root //_shipConstruct.Parts[0].localRoot.transform.RotateAround(launchTransform.position, axis, angle); //Create vessel object Debug.Log("CreateVesselObject"); Vessel _newVessel = _newConstructRootPart.localRoot.gameObject.AddComponent<Vessel>(); //Init from VAB _newVessel.Initialize(true); Debug.Log("Adding all the info to the ship"); //Attach vessel information _newVessel.id = Guid.NewGuid(); _newVessel.name = vesselName; _newVessel.Landed = true; _newVessel.Splashed = false; _newVessel.landedAt = string.Empty; _newVessel.situation = Vessel.Situations.LANDED; _newVessel.vesselType = VesselType.Debris; Vector3 vesselPosition = new Vector3(5f, 0f, 5f); //_newVessel.vesselName = _srcPart.vessel.vesselName + " - " + _shipConstruct.shipName; //_newVessel.landedAt = _srcPart.vessel.vesselName; //Store backup ShipConstruction.CreateBackup(_shipConstruct); Debug.Log("MissionIDStuff"); //Set Orbit //InitiateOrbit(vesselPosition, _newVessel); //Set Mission info Debug.Log("Set Mission ID"); uint missionId = (uint)Guid.NewGuid().GetHashCode(); //string flagUrl = _srcPart.flagURL; Debug.Log("Set Launch ID"); uint launchId = HighLogic.CurrentGame.launchID++; //Set part mission info for (int i = 0; i < _newVessel.parts.Count; i++) { Debug.Log("Loop through parts"); Part part = _newVessel.parts[i]; Debug.Log("Assign FlightID using ShipConstruction"); part.flightID = ShipConstruction.GetUniqueFlightID(FlightDriver.FlightStateCache.flightState); Debug.Log("Done it Once"); part.launchID = launchId; part.missionID = missionId; } Debug.Log("Finished Mission Stuff"); //Generate staging //Staging.beginFlight(); //_newConstructRootPart.vessel.ResumeStaging(); //Staging.GenerateStagingSequence(_newConstructRootPart.localRoot); //Staging.RecalculateVesselStaging(_newConstructRootPart.vessel); //Set position, again //_newVessel.SetPosition(launchTransform.position); //_newVessel.SetRotation(launchTransform.rotation); ////Get allll the parts, does it even matter since we launch from VAB? //for (int i = 0; i < _newVessel.parts.Count; i++) //{ // // Solar panels from containers (we dont have no bloody containers here tho) don't work otherwise // for (int j = 0; j < _newVessel.parts[i].Modules.Count; j++) // { // ConfigNode node = new ConfigNode(); // node.AddValue("name", _newVessel.parts[i].Modules[j].moduleName); // _newVessel.parts[i].LoadModule(node, ref j); // } //} Debug.Log("ProtoVesselStuff"); //Save Protovessel ProtoVessel _newProto = new ProtoVessel(_newVessel); Debug.Log("Defined ProtoVessel"); if (_newProto == null) { Debug.Log("Nope"); } else { Debug.Log("If Statement if not failed"); //Kill and remove spawned vessel, had some serious problems with spawn position warping/glitching _newVessel.Die(); //Set the protovessels position to the relative one we found, maybe redundant //_newProto.position = launchPos.transform.position; //If you check this value, you will see the height change from launch scene to resume scene, extra dafuq float height = _newProto.height; if (FlightDriver.StartupBehaviour == FlightDriver.StartupBehaviours.RESUME_SAVED_FILE || FlightDriver.StartupBehaviour == FlightDriver.StartupBehaviours.RESUME_SAVED_CACHE) { //Odd behaviour with positioning during different flight scenes, workaround awaaaay //_newProto.height = TrueAlt(launchTransform.position, _srcPart.vessel); } //Load Protovessel _newProto.Load(HighLogic.CurrentGame.flightState); // Restore ShipConstruction ship, otherwise player sees loaded craft in VAB ShipConstruction.ShipConfig = _OldVabShip.GetConfigNode(); //Fix Control Lock //FlightInputHandler.ResumeVesselCtrlState(FlightGlobals.ActiveVessel); //Fix active vessel staging //FlightGlobals.ActiveVessel.ResumeStaging(); } } /// <summary> /// http://forum.kerbalspaceprogram.com/threads/111116-KSP-Altitude-Calculation-Inquiry /// </summary> /// <returns></returns> //private float TrueAlt(Vector3 _LauncPos, Vessel _srcVessel) //{ // Debug.Log("Altitude Stuff?"); // //Vector3 pos = _srcPart.transform.position; //or this.vessel.GetWorldPos3D() // float ASL = FlightGlobals.getAltitudeAtPos(_LauncPos); // if (_srcVessel.mainBody.pqsController == null) { return ASL; } // float terrainAlt = Convert.ToSingle(_srcVessel.pqsAltitude); // if (_srcVessel.mainBody.ocean && _srcVessel.heightFromTerrain <= 0) { return ASL; } //Checks for oceans // return ASL - terrainAlt; //} /// <summary> /// https://github.com/taniwha-qf/Extraplanetary-Launchpads/blob/master/Source/BuildControl.cs /// https://github.com/taniwha-qf/Extraplanetary-Launchpads/blob/master/License.txt /// </summary> /// <param name="_newVessel"></param> /// <param name="_srcVessel"></param> //private void InitiateOrbit(Vector3 vesselPosition, Vessel _newVessel) //{ // Debug.Log("More OrbitStuff"); // var mode = OrbitDriver.UpdateMode.UPDATE; // _newVessel.orbitDriver.SetOrbitMode(mode); // // var craftCoM = GetVesselWorldCoM(_newVessel); // var vesselCoM = vesselPosition; // var offset = (Vector3d.zero + craftCoM - vesselCoM).xzy; // // var corb = _newVessel.orbit; // //var orb = _srcVessel.orbit; // var UT = Planetarium.GetUniversalTime(); // //var body = orb.referenceBody; // //corb.UpdateFromStateVectors(orb.pos + offset, orb.vel, body, UT); //Debug.Log(String.Format("[EL] {0} {1}", "orb", orb.pos)); // Debug.Log(String.Format("[EL] {0} {1}", "corb", corb.pos)); //} //public Vector3 GetVesselWorldCoM(Vessel v) //{ // var com = v.findLocalCenterOfMass(); // return v.rootPart.partTransform.TransformPoint(com); //} } } And here is the code I'm using to call the class etc. There are a few things that I will need to change later on down the line one I get the actual spawning part working. using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace TMS_Module_001 { [KSPAddon(KSPAddon.Startup.SpaceCentre, true)] public class TMS_Stargate : MonoBehaviour { public void Awake() { string vesselName = "namespace TMS_Module_001"; Vector3 vesselPosition = new Vector3(5f, 0f, 5f); VesselSpawner TMS_Module_001 = new VesselSpawner("namespace TMS_Module_001.craft", vesselName, vesselPosition); Debug.Log("Spawn the Ship"); TMS_Module_001.SpawnVessel(); } } } According to the Log, everything is getting called and running fine. However, there is a problem in the code which I can't seem to figure out how to fix (or at least undo what I've done to it) In the Log I see....... This exception is referring to this part of the code......(I've added a buttload of debug statements around this part to help identify the problem. for (int i = 0; i < _newVessel.parts.Count; i++) { Debug.Log("Loop through parts"); Part part = _newVessel.parts[i]; Debug.Log("Assign FlightID using ShipConstruction"); part.flightID = ShipConstruction.GetUniqueFlightID(FlightDriver.FlightStateCache.flightState); Debug.Log("Done it Once"); part.launchID = launchId; part.missionID = missionId; } Debug.Log("Finished Mission Stuff"); Specifically, line 6 in that block (part.flightID = ShipConstruction..........yadda yadda yadda) A weird side-effect of this is that it completely breaks the game. It creates an infinite for loop and messes everything else up (can't get off the Space Center screen :-O) Would anyone have any clue what's going on with that? Thanks TheMightySpud
  25. Apologies, forgot to address @wasml's comments. I've looked at a bunch of 'spawning' mods, but to be completely honest, I can't make head nor tail of any of them. I'm still very new to the whole class thing and find it really confusing as to what's referencing what etc. (especially in other people's code). I'm primarily a Modeller but do have a little background in coding (PHP/HTML, a little vb.net, a little python etc) but nothing as complicated as some of the things I've seen on here. lol. TheMightySpud
×
×
  • Create New...