Jump to content

Best way to start making mods?


Recommended Posts

I want to start making mods but can't seem to find anywhere that will help me start. I'm aware of this thread, but after following it, it doesn't seem to work. After following it my VS keeps complaining that it can't find MonoBehaviour or anything.

Gtb5loqOPT.png

The code being this:

using System;
using UnityEngine;

namespace MyMod
{
	[KSPAddon(KSPAddon.Startup.MainMenu, false)]
    public class MyClass : MonoBehaviour 
    {
		public void Update() 
		{
			Debug.Log("Hello world! " + Time.realtimeSinceStartup);
		}
    }
}

+ the correct references (at least from what that tutorial says)

lJhuk5OULe.png

I've also tried this wiki thread, no luck there. I've tried installing Mono to see if Unity failed there - no luck. I honestly don't know where to look at this point. Any help is appreciated. :)

Link to comment
Share on other sites

Quote

You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Try that; I think that one is called "System". These are the references that I needed to compile with KSP 1.9:

https://github.com/HebaruSan/Astrogator/blob/3dad7c80315926c820ebfd1367b60f4db49deb9d/src/Astrogator.csproj#L39-L79

In general, the easiest way to get started is to download an existing mod and work on compiling it; since someone else has already gone to the trouble of making sure the code is correct, any problems will be caused by your environment.

Link to comment
Share on other sites

Managed to compile that Astrogator project you sent pretty much immediately, so I started messing about with my .csproj file. After a while I managed to get my mod compiling and sending debug info, so was my fault. Thanks man :)

For any one else who happens to be struggling with this kind of thing too, adding this to the top of my file will make it work. (targeting net 4.7)

<PropertyGroup>
  <OutputType>Library</OutputType>
  <AppDesignerFolder>Properties</AppDesignerFolder>
  <RootNamespace>MyMod</RootNamespace>
  <AssemblyName>MyMod</AssemblyName>
  <TargetFramework>net47</TargetFramework>
</PropertyGroup>

 

Edited by Livaco
Bad grammar
Link to comment
Share on other sites

  • 3 weeks later...

couple of notes:

.NET 3.5 for KSP 1.7 and earlier

.NET 4.+ for post KSP 1.7

also you can do this:

I define an environmental variable to point to my Dev installs.

  • DevDir17 = KSP173
  • DevDir18 = KSP18
  • DevDir19 = KSP19

and then in the .csproj:
 

  <ItemGroup>
    <Reference Include="$(DevDir173)\KSP_x64_Data\Managed\Assembly-CSharp*.dll">
      <Private>False</Private>
    </Reference>
    <Reference Include="$(DevDir173)\KSP_x64_Data\Managed\UnityEngine*.dll">
      <Private>False</Private>
    </Reference>
    <Reference Include="$(DevDir173)\KSP_x64_Data\Managed\UnityEngine.UI.dll">
    </Reference>
    <Reference Include="$(DevDir173)\GameData\000_Toolbar\Plugins\aaa_Toolbar.dll">
      <Private>False</Private>
    </Reference>
    <Reference Include="$(DevDir173)\GameData\000_ClickThroughBlocker\Plugins\ClickThroughBlocker.dll">
      <Private>False</Private>
    </Reference>
    <Reference Include="$(DevDir173)\GameData\001_ToolbarControl\Plugins\ToolbarControl.dll">
      <Private>False</Private>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Xml.Linq" />
  </ItemGroup>

this is for 'Biomatic' one of my adopted mods (from @Biff Space)

kindly note the wildcard '*' in the filename. It works to draw in all others. I rather have too much included, than not enough, especially since a smart compiler only keeps what it needs.

Also the <Private>False</Private> tell the compiler to not copy the .dll when it compiles.

I use the environmental variable for several reasons:

1. so others can recompile the code much easier

2. more importantly, so I can can develop and maintain multiple versions of the same mod - for different versions of KSP)

Edited by zer0Kerbal
Link to comment
Share on other sites

On 3/16/2020 at 2:10 AM, HebaruSan said:

In general, the easiest way to get started is to download an existing mod and work on compiling it

I just want to point out that all the VS solutions come with a set of unique GUIDs, which will end up to your dll. It is always a good idea to keep the GUIDs unique, even though I never heard of any actual issues of several dlls having the same GUID. Still, if you start your mod based on someone else's sources, you should probably re-generate all the GUIDs. Also, don't forget about the license, which should remain compatible.

Link to comment
Share on other sites

6 minutes ago, Morse said:

I just want to point out that all the VS solutions come with a set of unique GUIDs, which will end up to your dll. It is always a good idea to keep the GUIDs unique, even though I never heard of any actual issues of several dlls having the same GUID. Still, if you start your mod based on someone else's sources, you should probably re-generate all the GUIDs. Also, don't forget about the license, which should remain compatible.

I'm not necessarily advocating modifying an existing mod to produce a new one (though that is an option, with the caveats you mention). Just compiling an existing mod as-is can help with understanding and validating the build environment.

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