Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

38 minutes ago, Benjamin Kerman said:

@Apaseall So what you're going to want to do is make a new solution, create a new project inside of that, and set it to compile to a project library (.dll).

I'd strongly recommend trying it with someone else's already working project first (all KSP mods have source code available). That way you know that any problems you encounter are in your environment setup rather than in the code. Then once you're able to compile an existing mod, you can start your own project confident that all the problems are in the new code.

Link to comment
Share on other sites

At this point I am more concerned with making sure I have all the things I need to get started.
For example it was not overly clear that I needed to add the .NET part to VS.
Yes I read that I need to add the Unit part.
But when I came to set the class I was trying to find Installed > Templates > Visual C# > Windows  from here :https://wiki.kerbalspaceprogram.com/wiki/Setting_up_Visual_Studio

Later when trying to download DevHelper from here:https://steamcommunity.com/sharedfiles/filedetails/?id=435932924

Then trying to speed up load time by deleting stuff from /squad/parts and /squad/spaces, also found in the steam link just above.

Here is a different question.
I see I have a folder called Unity 2018.1.6f1 (64-bit).
But does that refer to KSP 1.5 only?
I want to still work on stuff in 1.4.5.
Will I have to do something interesting to be able to do that?

Link to comment
Share on other sites

On 10/19/2018 at 1:04 AM, Apaseall said:

At this point I am more concerned with making sure I have all the things I need to get started.

This all assumes you are writing a plugin (I have literally no experience making parts) and are running Windows. (warning - image heavy)

Diazo's thread does cover this, but this is more specific to VS 2017.

First make sure you have .Net Framework 3.5 installed (you can do this through "turn Windows Features on or off")

In Visual Studio Installer you need to install the.Net Desktop Environment

feoiUEN.png

Then, in Individual Components, you install .Net Framework 3.5 development tools (this will not show up if you don't have .Net 3.5 installed)

svlee0e.png

Once that's installed, Start up VS and click File>New>Project

Select Class Library (.Net Framework) and select .Net Framework 3.5 at the bottom.

FBk1hpe.png

Once your solution has been created/loads, in your Solution Explorer right click on "references" then click "Add Reference"

Click on Browse

Navigate to <Your KSP folder>/KSP_x64 data/Managed

Select (using CTRL to select multiple if necessary) Assemble-Csharp.dll, Assembly-Csharp-firstpass.dll, UnityEngine.dll, UnityEngineUI.dll - then click Add, Then OK.

At this point your solution is ready, and you can use the the link provided by Benjamin Kerman as a guide to create the type of mod you want.

Quote

I see I have a folder called Unity 2018.1.6f1 (64-bit).
But does that refer to KSP 1.5 only?

No. KSP is using 2017.1.3p1 - if you want to use the Debug Tools in this thread you will need to install the same version of Unity. You won't need to change your Unity version for 1.4.5/1.5 as they use the same version. If KSP updates Unity again in the future, you will need to update this. Incidentally, you can always check what version of Unity KSP is using, by looking at your output_log file. There will be a line that says something like: Initialize engine version: 2017.1.3p1

Edited by severedsolo
Link to comment
Share on other sites

2 hours ago, severedsolo said:

This all assumes you are writing a plugin (I have literally no experience making parts) and are running Windows. (warning - image heavy)

First make sure you have .Net Framework 3.5 installed (you can do this through "turn Windows Features on or off")

Yes I plan on making and or editing plugins.
.Net Framework exists as at least 3.5 and 3.5.1, there is also something about service pack 1?
Therefore when you write 3.5 which version do you mean?

Link to comment
Share on other sites

On 10/19/2018 at 1:04 AM, Apaseall said:

 

 

36 minutes ago, Apaseall said:

Yes I plan on making and or editing plugins.
.Net Framework exists as at least 3.5 and 3.5.1, there is also something about service pack 1?
Therefore when you write 3.5 which version do you mean?

Bah stupid indestructible quote boxes. Just go into "turn windows features on or off" and tick the box next to. Net Framework 3.5 (including 2.0) - on mobile so can't check exact name, but that's the gist. Windows will then get the latest version for you.

Link to comment
Share on other sites

2 hours ago, severedsolo said:

Bah stupid indestructible quote boxes. Just go into "turn windows features on or off" and tick the box next to. Net Framework 3.5 (including 2.0) - on mobile so can't check exact name, but that's the gist. Windows will then get the latest version for you.

On my PC in the place mentioned I only see .Net 3.5.1. It has a blue square box next to it. It expands to show two sub options; Windows Communication Foundation HTTP Activation and Windows Communication Foundation non-HTTP Activation. Both of those are not ticked.
I presume that I do not need those sub options.
But I am right back to asking 3.5? This does not exist for me. 3.5.1 does.
Do I need to download and install .Net 3.5, which I have a download file called detNetFx35setup.exe?
I am not sure how sensitive "IT" is to version, i.e. will 3.5.1 produce odd behavior, or is it ok to use any 3.5.x version?

Edited by Apaseall
Link to comment
Share on other sites

27 minutes ago, maja said:

Guys, I'm at lost here. I'm trying for three days to save a position of a PopupDialog (like @HebaruSan does this in his Astrogator mod), but to no avail. Can some look at my code and tell me, what's wrong there?

Source code is here: https://github.com/jarosm/KSP-BonVoyage/tree/devel/BonVoyage

Do you mean save it between sessions, or during the same session? If the former, you'd have to save and load MainWindowModel.MainWindowPosition to/from a file somewhere. The Settings object does that for Astrogator:

https://github.com/HebaruSan/Astrogator/blob/0bb22564957534be0b27e7c36780b5c87427b734/src/Settings.cs#L18-L40

There may be ways to create an object that the core game will auto-save/load for you, but I haven't worked with them.

Link to comment
Share on other sites

3 minutes ago, HebaruSan said:

Do you mean save it between sessions, or during the same session? If the former, you'd have to save and load MainWindowModel.MainWindowPosition to/from a file somewhere. The Settings object does that for Astrogator:

https://github.com/HebaruSan/Astrogator/blob/0bb22564957534be0b27e7c36780b5c87427b734/src/Settings.cs#L18-L40

There may be ways to create an object that the core game will auto-save/load for you, but I haven't worked with them.

Right now I need to preserve it's position in the same scene when user closes the dialog and then opens it again. Persisting them between sessions will come later and it's not a problem (I know how to do it).

Maybe I'm missing something, but it seems, that the new values for the position are ignored and only the starting ones are used. I checked once more, that the new values are availaible when MultiOptionDialog needs them.

Link to comment
Share on other sites

41 minutes ago, maja said:

Right now I need to preserve it's position in the same scene when user closes the dialog and then opens it again. Persisting them between sessions will come later and it's not a problem (I know how to do it).

Maybe I'm missing something, but it seems, that the new values for the position are ignored and only the starting ones are used. I checked once more, that the new values are availaible when MultiOptionDialog needs them.

So MultiOptionDialog is just ignoring its Rect parameter? Sorry, I haven't seen that happen, and I don't see anything in your code that looks like it would cause that. Is it putting the window in the exact same spot every time?

Link to comment
Share on other sites

1 hour ago, HebaruSan said:

So MultiOptionDialog is just ignoring its Rect parameter? Sorry, I haven't seen that happen, and I don't see anything in your code that looks like it would cause that. Is it putting the window in the exact same spot every time?

Yes, exactly in the same spot depending on the anchor parameters. It looks like the dialog's anchor point is always positioned to the center of the screen. Only the width and height of the dialog is changing. Just for the record, UI scale is 100%.

I tried your mod in my clear devel install of KSP before posting and it was behaving like expected. Where I leaved the window, there it was after reopening.

Link to comment
Share on other sites

How to add new runtime info-strings in the flight part-right-click menu for stock modules?
For example, some additional info for parts with ModuleScienceConverter and ModuleScienceLab?
Do I need to create a new module ModuleScienceInfo, attach to the parts using the ModuleManager, and work in the ModuleScienceInfo?

Edited by flart
Link to comment
Share on other sites

@Benjamin Kerman @0111narwhalz 

Yes, I can create a new PartModule, add to parts using MM-patch, create new fields in the code
using 
KSPField[guiActive = true], and filled the fields with whatever values I want. 

But It looks like overdoing for just showing few strings for an existing stock PartModule.

P. S.
a runrime strings, I mean they can change on Unity.update(), or at least, on some KSPEvent()

Edited by flart
Link to comment
Share on other sites

4 hours ago, peteletroll said:

I wrote a PartModule with a sound effect in it. The sound doesn't fade with camera distance! I googled out something about AudioSource and AudioListener, but couldn't find any KSP related example. Any help? Thanks!

Figured it out! Must set AudioSource spatialBlend to 1.0f.

Link to comment
Share on other sites

  • 2 weeks later...

I have an issue with Visual Studio Community 2017 (v15.8.9). I had to reinstall the system and installed VS anew. Now, it doesn't open my mods projects because ".NET Framework 3.5 is not installed on this machine". In fact I have installed .NET dev pack 3.5 and .NET Runtime 3.5. I don't remember this problem in the past. What am I doing wrong?

Link to comment
Share on other sites

  • 2 weeks later...
6 hours ago, CrayzeeMonkey said:

Is there an elegant way to disable collisions for an entire vessel? Just setting the rigidbody detectCollisions false on all the parts of a vessel seems problematic (nullrefs are thrown).

I'm using this, when moving vessels up/down through terrain:

// Vessel v
v.ResetCollisionIgnores();

// execution code here

v.ResetGroundContact();
v.IgnoreGForces(20);
v.SetWorldVelocity(Vector3.zero);
v.angularMomentum = Vector3.zero;
v.angularVelocity = Vector3.zero;
VesselSleep(v);

-------------------------------------
  
private static void VesselSleep(Vessel v)
{
  foreach (Part p in v.parts)
  {
    if (p.Rigidbody != null)
      p.Rigidbody.Sleep();
  }
}

 

Link to comment
Share on other sites

Hi, I'm trying to control my rover. I'm able to make it drive straight forward by modifying the wheelThrottleTrim and pitchTrim fields from Vessel.ctrlState. However, I couldn't get the rover to steer by modifying the wheelSteerTrim and yawTrim fields.

void Update()
{
  FlightCtrlState vesselCtrl = FlightGlobals.ActiveVessel.ctrlState;

  vesselCtrl.wheelThrottleTrim = this.Drive;
  vesselCtrl.pitchTrim = this.Drive;

  vesselCtrl.wheelSteerTrim = -1f*this.Steer;
  vesselCtrl.yawTrim = this.Steer;
}

The Steer property is modified by some button listeners, and gets the value -1f if steering left and 1f if steering right. The sign of wheelSteerTrim field is inverted, because the steer direction of my wheels are also set to inverted (this is the way it would be if I gave user input and observed the ctrlState object through a debugger).

Also, here's a picture of a the rover I'm using to test my  mod:

e5q3ptr.png

So the problem is: I can't steer the wheels through an instance of the FlightCtrlState class. Am I missing something here?

Edited by Hydrawx
Link to comment
Share on other sites

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