Jump to content

Quicker feedback loop during testing?


Recommended Posts

Hi, I'm new to KSP/Unity (but using .NET every day as a job) so naturally I'm running into a few exceptions during my testing of the waters - exacerbated by the absence of API docs although Anatid's community docs are a great find, sparse in parts but still very helpful.

So far the only way I've found to test my code is to compile to a class lib in an addon folder and start KSP. After I find a problem I'll close KSP, wait a minute for the mem usage to clear, apply changes, recompile, restart ksp and start flying a new vessel to check my flight-scene changes. At this point I'll probably catch another Exception, and then I'll close KSP, wait a minute... and now it's 1 in the morning.

Am I missing some magical Unity shortcut to re-link my addon after changes without restarting the game? Any tips for shortening my testing cycle? I'm not new to modding but I've never had this much trouble just getting something running in a game with a public mod api. I like this game and I want to make a few of my ideas happen, but right now I'm spending more time waiting than developing!

Thanks all, I'm doubly impressed with what you've done so far if there's no way around this :cool:

Link to comment
Share on other sites

That the way I do it. My own research suggests the assembly loader does not support dynamically loading plugins, so we are a bit stuck.

There are one or two tricks, though:

Giving a class variable the [KSPField] attribute lets you change its value in the module declaration in part.cfg:


[KSPField]
public float myVariable;


MODULE
{
name = myClass
myVariable = 6.6
}

So you can use the ALT+F12 menu to reload parts in game after changing the value in the part.cfg

Sirkut has written a mod helper plugin that allows you to go straight to a SPH/VAB etc. without going through the save and scene selection on load.

Keep a dev copy of KSP stripped of most parts so it loads quicker.

And make extensive use of the debug menu and gui fields for keeping track of variables.

You probably know at least some of that already, but there it is for reference.

Good luck! Anything particular you're struggling with?

Link to comment
Share on other sites

Hunting down exceptions is hard, especially if you fall into the trap of long Update/OnUpdate/OnStart methods, since the error log will only tell you that the expection happened somewhere in that method.

If you break up the method into smaller chunks, you will be told which sub-method it happened in instead, making it much easier to find the place where it failed.

The difference between


public override OnUpdate()
{
// 100 instructions
}

-> NullReference Exception in OnUpdate

and


public override OnUpdate()
{
bunny = Dothis();
DoThat(bunny);
nowFinishHim();
}

-> NullReference Exception in DoThat(object target) in OnUpdate()

is five hours down the drain searching in the wrong place

Link to comment
Share on other sites

Great advice, thanks for all of it - I'll put this into use when I get back home.

I was thinking about the one-time dll link issue at work and I had a little idea - does ksp's distro of mono support AppDomains? Could write something in a primary class lib to load a second lib via an AppDomain, which I understand at first glance could lead to runtime hot-swapping of behaviour, big perf hit through marshalling but good enough for development. Thoughts? If it sounds feasible I can poke away at that for a bit.

Link to comment
Share on other sites

I swear I posted this yesterday, must have not hit post or maybe my internet went out:

You do have to recompile and restart KSP for testing plugins unfortunately. I'm not sure why you need to 'wait a minute for the mem usage to clear' though, I've never done that.

You can speed up the process by making a copy of your KSP and then stripping out a lot of the parts so that they dont need to be loaded, this will speed up the time it takes for you to load the game. You just copy the install directory, then go into 'Kerbal Space Program/GameData/Squad/Parts' and remove some of the part that you dont need for testing. Also be sure to remove any addons you have installed if you can do without them.

There was also some code you could put in your addon/an addon to cause the game to automatically load one of your save files right from the menu, so you skips those, but I haven't tried it so you'll have to look it up yourself in the forums if you want to do that.

Link to comment
Share on other sites

I knocked up a few things a while ago that contain some more detail on a number of those tips: http://forum.kerbalspaceprogram.com/threads/66503 - the blog entries in particular.

Although I didnt know sirkut had made some extra stuff jump to SPH and VAB bits so I'm off to look for those now

EDIT: One follow on - be aware that if you load a save and jump to it from the main menu directly some of the game components can be uninitialised from 0.24 onwards - most noticably the contracts system. I am trying to work out a new method that jumps through the right scenes to get to my result

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