Jump to content

Example plugin projects to help you get started


Recommended Posts

Well first of all, thank you for this :kiss:

I'm very new to KSP Plugin development, but have some C# experience; I'm looking at the first sample right now (partless), and what strikes me as odd is that the methods are declared like this:


void FixedUpdate() {}

Shouldn't they override the base methods, as in


public override void OnFixedUpdate() {}

Or is there something I'm missing about the way the KSP API is being called?

Edited by daniu
Link to comment
Share on other sites

Those are called by unity from unmanaged code through reflection (or rather the native API).

Incidentally, not making them public or at least protected gives a bad example, because the compiler won't even produce a warning when you override them in a subclass, and if it happens to something like OnDestroy, it might be hard to notice. I found numerous places where that happened in KAS, and it likely contributed to its explody tendencies.

Link to comment
Share on other sites

Thanks :)

So does the override version not work at all, or is it only not common practice/discouraged/bad style?

Or should it be fine (as long as I don't forget base.OnFixedUpdate() probably)?

Link to comment
Share on other sites

  • 1 year later...

Trying to get this to work, but it's not compiling. For one thing, three of the references are missing; Assembly-CSharp, Assembly-CSharp-firstpass and UnityEngine. Also I'm wondering where the KSPAddon class is supposed to come from. Anyone got any thoughts on these issues?

Link to comment
Share on other sites

52 minutes ago, PhamNuwen said:

Trying to get this to work, but it's not compiling. For one thing, three of the references are missing; Assembly-CSharp, Assembly-CSharp-firstpass and UnityEngine. Also I'm wondering where the KSPAddon class is supposed to come from. Anyone got any thoughts on these issues?

Alright, I found the solution myself. Just replace the three references I mentioned with references to the dlls of the same name in the ...\Kerbal Space Program\KSP_Data\Managed folder. Maybe you could add this information to the readme, that would make it a lot easier for future users to get this running.

Link to comment
Share on other sites

  • 3 months later...
  • 5 months later...

I'm just starting out with trying to learn how to make a simple plugin and having a look at these examples. I've got MonoDevelop setup in Linux and am attempting to build the first example.  At first I got some errors about not being able to reference UnityEngine, but that was fixed by updating the references.  Now on build I get a single error which I don't understand;

/usr/lib/mono/4.5/Microsoft.Common.targets: Error: Command 'call /home/sujimichi/coding/mono/TacExamples/01-SimplePartlessPlugin/Source/PostBuild.bat /home/sujimichi/coding/mono/TacExamples/01-SimplePartlessPlugin/Source/' exited with code: 127. (01-SimplePartlessPlugin)

If I expand the references section System.Core, System.Data.DataSetExtensions and System.Xml.Linq all have a red cross by them and when I hover over them it says "Framework Mono / .NET 3.5 is not installed" but from what I understand mono now only supports .NET 4.5 so is that another reference that I need to change or do I need to use 3.5 (and if so how do I set that up)?

Thanks @TaranisElsu for setting these examples up, I can see that once I get over the initial setup hurdles that they are going to be very helpful. 

Link to comment
Share on other sites

On 03/09/2016 at 0:47 AM, katateochi said:

I'm just starting out with trying to learn how to make a simple plugin and having a look at these examples. I've got MonoDevelop setup in Linux and am attempting to build the first example.  At first I got some errors about not being able to reference UnityEngine, but that was fixed by updating the references.  Now on build I get a single error which I don't understand;


/usr/lib/mono/4.5/Microsoft.Common.targets: Error: Command 'call /home/sujimichi/coding/mono/TacExamples/01-SimplePartlessPlugin/Source/PostBuild.bat /home/sujimichi/coding/mono/TacExamples/01-SimplePartlessPlugin/Source/' exited with code: 127. (01-SimplePartlessPlugin)

If I expand the references section System.Core, System.Data.DataSetExtensions and System.Xml.Linq all have a red cross by them and when I hover over them it says "Framework Mono / .NET 3.5 is not installed" but from what I understand mono now only supports .NET 4.5 so is that another reference that I need to change or do I need to use 3.5 (and if so how do I set that up)?

Thanks @TaranisElsu for setting these examples up, I can see that once I get over the initial setup hurdles that they are going to be very helpful. 

Yep you are guessing right. You have to use an older version of mono on linux that supports .NET 3.5. Because that's what you need.
This might help.
http://blog.rubenwardy.com/2016/07/20/rimworld-install-monodevelop-with-dot-net-3.5/

Link to comment
Share on other sites

13 minutes ago, JPLRepo said:

Yep you are guessing right. You have to use an older version of mono on linux that supports .NET 3.5. Because that's what you need.
This might help.
http://blog.rubenwardy.com/2016/07/20/rimworld-install-monodevelop-with-dot-net-3.5/

Thanks! 
so, in my noobish blundering around, I started a new solution (in the .NET 4.5 setup I have), set the references (to Assembly-CSharp and UnityEngine) and just copied the parts of the example I was interested in into the new solution.  Then hit build and it built the project and I was able to copy the resultant .dll into KSP and it ran as expected (and now I've taken it further with experiments with a partless mod that produces a GUI window and that's still working ok).  
Can I just carry on like this, or is it an absolute must to downgrade to .NET 3.5?

Link to comment
Share on other sites

2 minutes ago, katateochi said:

Thanks! 
so, in my noobish blundering around, I started a new solution (in the .NET 4.5 setup I have), set the references (to Assembly-CSharp and UnityEngine) and just copied the parts of the example I was interested in into the new solution.  Then hit build and it built the project and I was able to copy the resultant .dll into KSP and it ran as expected (and now I've taken it further with experiments with a partless mod that produces a GUI window and that's still working ok).  
Can I just carry on like this, or is it an absolute must to downgrade to .NET 3.5?

Yeah, the DLLs won't fail to load--they will load. They'll just break badly when you try to do anything not in NET 3.5.
I'd recommend downgrading and making sure your project is set to .NET 3.5 target.

Link to comment
Share on other sites

2 minutes ago, JPLRepo said:

Yeah, the DLLs won't fail to load--they will load. They'll just break badly when you try to do anything not in NET 3.5.
I'd recommend downgrading and making sure your project is set to .NET 3.5 target.

ok, shall do. Thanks for the help!

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