Setting up Unity: Difference between revisions

From KSP 2 Modding Wiki
(Added Installing the addressables)
(Unity project creation instructions and page cleanup)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This page will help you install everything you need to work your on Unity.
This page will help you install everything you need to use Unity for KSP2 modding.


== Installing Unity ==
== Installing Unity ==


# Download Unity Hub. https://unity.com/download
# Download Unity Hub from https://unity.com/download.
# Download Unity 2022.3.5f1. https://unity.com/releases/editor/whats-new/2022.3.5
# Download Unity 2022.3.5f1 by clicking on the '''Install this version with Unity Hub''' link on this page: https://unity.com/releases/editor/whats-new/2022.3.5.
# Click on “Install this version with Unity Hub”.
# Download and install Git from https://git-scm.com/downloads.


== Initializing the Unity project ==
== Initializing the Unity project ==
As the Unity project is very large (~4 GB), we will use it for all our mods.
# Open '''Unity Hub'''.
 
# Click on '''New Project''' at the top right of the window.
# Follow the instructions on this page : https://luxstice.notion.site/Creating-a-Unity-Project-dae1a51ab2a84fc4b5c5e1eeef4b90b3.
# At the top of the new interface, set the '''Editor Version''' to <code>2022.3.5f1</code>. You can keep the project template set to '''3D (Core)'''.
# Set the '''Project name''', it can be whatever you want like for example <code>MyModId.Unity</code>.
# Set the '''Location''' to the folder you want the Unity project to be saved in.
# Click '''Create project'''.


<blockquote>For a quick presentation of the Unity interface: https://luxstice.notion.site/Learning-Unity-faf0ab10f24c4925bf4b51a997a41666.</blockquote>
<blockquote>For a quick presentation of the Unity interface: https://luxstice.notion.site/Learning-Unity-faf0ab10f24c4925bf4b51a997a41666.</blockquote>


== Configure the Unity project ==
== Configuring the Unity project ==
 
=== Installing the addressables package ===
Unity doesn’t come with this package natively, so we need to install it. Its easy!


# You start by going into ''Window>Package Manager'' on the top left area of Unity.
=== Installing the Addressables package ===
# This will open a new window where you can manage '''''almost''''' all the packages inside Unity.
Unity doesn’t come with this package natively, so we need to install it first:
# Go where it says '''Packages: In Project''' and change that to '''Unity Registry.'''
# On the search bar, look for '''Addressables'''. Select it and click install! It will show a couple pop-ups, and once its finished, it will show a green checkmark next to the Addressables’s version.


=== Importing ThunderKit ===
# Open the Package Manager by clicking '''Window>Package Manager''' in the toolbar at the top of Unity.
ThunderKit is a package for unity. but its instalation is a bit different from the usual.
# This will open a new window where you can manage most of the packages in your project.
# Go where it says '''Packages: In Project''' and change that to '''Unity Registry'''.
# In the search bar, look for '''Addressables'''. Select it and click '''Install'''. It will show a couple pop-ups, and once it is finished, it will show a green checkmark next to the '''Addressables''' package version.


# Download the latest version of ThunderKit here : https://github.com/KSP2Community/ThunderKitInstaller/releases.
=== Installing ThunderKit ===
# Open the file with Unity Hub. When Unity opens, choose "Import" in the import window.
''ThunderKit'' is a package for Unity which we use to import the game's components into the Unity editor. However, it is not hosted in the official Unity package repository and needs to be installed directly from its GitHub repository.
# The ThunderKit Settings window should open, if it doesn’t just go to '''Tools>Thunderkit>Settings''' on the top part of Unity.
# Go to '''Import Configuration''' and on '''Import Project Settings''' change the dropdown to '''Nothing.'''
# Go to '''ThunderKit Settings''' and on '''Locate and load game files for project''' click on '''Browse''' and select your '''main''' Kerbal Space Program 2 executable ('''KSP2_x64.exe''').
# Click '''Import''' and wait for KSP2 to be imported, if asked click '''I made a backup, Go Ahead'''
# If Unity asks you to restart your project, click '''Restart Project'''
# To check if the game was correctly imported, select any game object and on the inspector click '''Add Component''' then search for '''Core Part Data'''.


Sometimes, the component wont appear right after the import, if so:
# Go to '''Window>Package Manager''' and click on the '''+''' sign in the top left corner of the window that opens, after that click on '''Add Package from Git URL''', paste <code>https://github.com/PassivePicasso/ThunderKit.git</code> and click '''Add'''.
1. Go to your Project window on unity
# The ''ThunderKit'' Settings window should open, if it doesn’t, just go to '''Tools>ThunderKit>Settings''' in the toolbar at the top of Unity.
2. Open the Packages tree view and scroll to KSP2_x64
# Go to '''Import Configuration''' and in '''Import Project Settings,''' change the dropdown value to '''Everything.'''
3. Right click and select "Reimport" (DON’T SELECT REIMPORT ALL, it takes way longer)
# Go to '''ThunderKit Settings''' and in '''Locate and load game files for project,''' click on '''Browse''' and select your main Kerbal Space Program 2 executable found at <code><KSP2 root folder>/KSP2_x64.exe</code>.
4. Wait for the folder to be reimported, once finished you should be good to go
# Click '''Import''' and wait for KSP2 to be imported. If asked, click '''I made a backup, Go Ahead'''.
# If Unity asks you to restart your project, confirm it by clicking on '''Restart Project'''.
This also fixes if Unity looses track of KSP2’s components like so. If your components look like this, do the same shown above.
# After the process is finished, to check if the game was correctly imported, select or create any game object and in the inspector click '''Add Component''' and search for '''Core Part Data'''.


=== Importing Unity KSP tools ===
=== Installing KSP2 Unity Tools ===


# Download the package here : https://github.com/SpaceWarpDev/KSP2UnityTools/releases.
# Go to '''Window>Package Manager''' and click on the '''+''' sign in the top left corner of the window that opens, after that click on '''Add Package from Git URL''', paste <code>https://github.com/KSP2Community/KSP2UnityTools.git</code> and click '''Add'''.
# Click on the download file then click on “Import”.
If you have previously installed an older version of KSP2 Unity Tools manually from a .unitypackage file, you will need to delete the whole "KSP2UnityTools" folder from your Assets folder and then do the installation.


=== Other configurations ===
=== Setting up swinfo.json and addressables ===


# In the project explorer, go to Assets > AddressablesAssetData > AssetGroups > Built In Data.
# After installing KSP2UnityTools, go to '''Tools>KSP2 Unity Tools.'''
# In the Inspector window, click on “Inspect Top Level Settings”.
# Follow one of two following steps, depending on which applies for you:
# Set the “Shader Bundle Naming Prefix” field to “Default Group GUID”.
# '''If you have a mod you want to copy addressables into''':
## Set '''Build Mode''' to "'''Copy Assets Only'''".
## In the build path select the <code>addressables</code> folder in your mod's directory.
## At the bottom of the window, press '''Import swinfo.json''' and select your mod's <code>swinfo.json</code>.
# '''If you want to build a full mod from Unity''':
## Set '''Build Mode''' to "'''Everything'''".
## Set build path to where you want to output your packaged mod (you can set this later, just set it before build).
## If you already have a swinfo.json file, you can skip the next steps using the import swinfo.json button as described in the previous section.
## Input your mod's ID (this is critically important).
## Setup the rest of your mod's info (these correspond to the swinfo).
# After following one of the previous two processes, press '''Set Up Addressables From Mod Info''', and it should automatically set up the addressables groups for you.


<blockquote>Without this manipulation, Unity generates bundles with an ID calculated from the project name. Since we are using the same project for multiple mods, there will be a name conflict for the standard shader that Unity incorporates into all addressables. Using the GUID of the default group will help avoid collisions (you will need to remember to make the mod group the default group).</blockquote>
[[Category:Getting started]]
[[Category:Getting started]]

Latest revision as of 07:58, 21 February 2024

This page will help you install everything you need to use Unity for KSP2 modding.

Installing Unity

  1. Download Unity Hub from https://unity.com/download.
  2. Download Unity 2022.3.5f1 by clicking on the Install this version with Unity Hub link on this page: https://unity.com/releases/editor/whats-new/2022.3.5.
  3. Download and install Git from https://git-scm.com/downloads.

Initializing the Unity project

  1. Open Unity Hub.
  2. Click on New Project at the top right of the window.
  3. At the top of the new interface, set the Editor Version to 2022.3.5f1. You can keep the project template set to 3D (Core).
  4. Set the Project name, it can be whatever you want like for example MyModId.Unity.
  5. Set the Location to the folder you want the Unity project to be saved in.
  6. Click Create project.

For a quick presentation of the Unity interface: https://luxstice.notion.site/Learning-Unity-faf0ab10f24c4925bf4b51a997a41666.

Configuring the Unity project

Installing the Addressables package

Unity doesn’t come with this package natively, so we need to install it first:

  1. Open the Package Manager by clicking Window>Package Manager in the toolbar at the top of Unity.
  2. This will open a new window where you can manage most of the packages in your project.
  3. Go where it says Packages: In Project and change that to Unity Registry.
  4. In the search bar, look for Addressables. Select it and click Install. It will show a couple pop-ups, and once it is finished, it will show a green checkmark next to the Addressables package version.

Installing ThunderKit

ThunderKit is a package for Unity which we use to import the game's components into the Unity editor. However, it is not hosted in the official Unity package repository and needs to be installed directly from its GitHub repository.

  1. Go to Window>Package Manager and click on the + sign in the top left corner of the window that opens, after that click on Add Package from Git URL, paste https://github.com/PassivePicasso/ThunderKit.git and click Add.
  2. The ThunderKit Settings window should open, if it doesn’t, just go to Tools>ThunderKit>Settings in the toolbar at the top of Unity.
  3. Go to Import Configuration and in Import Project Settings, change the dropdown value to Everything.
  4. Go to ThunderKit Settings and in Locate and load game files for project, click on Browse and select your main Kerbal Space Program 2 executable found at <KSP2 root folder>/KSP2_x64.exe.
  5. Click Import and wait for KSP2 to be imported. If asked, click I made a backup, Go Ahead.
  6. If Unity asks you to restart your project, confirm it by clicking on Restart Project.
  7. After the process is finished, to check if the game was correctly imported, select or create any game object and in the inspector click Add Component and search for Core Part Data.

Installing KSP2 Unity Tools

  1. Go to Window>Package Manager and click on the + sign in the top left corner of the window that opens, after that click on Add Package from Git URL, paste https://github.com/KSP2Community/KSP2UnityTools.git and click Add.
If you have previously installed an older version of KSP2 Unity Tools manually from a .unitypackage file, you will need to delete the whole "KSP2UnityTools" folder from your Assets folder and then do the installation.

Setting up swinfo.json and addressables

  1. After installing KSP2UnityTools, go to Tools>KSP2 Unity Tools.
  2. Follow one of two following steps, depending on which applies for you:
  3. If you have a mod you want to copy addressables into:
    1. Set Build Mode to "Copy Assets Only".
    2. In the build path select the addressables folder in your mod's directory.
    3. At the bottom of the window, press Import swinfo.json and select your mod's swinfo.json.
  4. If you want to build a full mod from Unity:
    1. Set Build Mode to "Everything".
    2. Set build path to where you want to output your packaged mod (you can set this later, just set it before build).
    3. If you already have a swinfo.json file, you can skip the next steps using the import swinfo.json button as described in the previous section.
    4. Input your mod's ID (this is critically important).
    5. Setup the rest of your mod's info (these correspond to the swinfo).
  5. After following one of the previous two processes, press Set Up Addressables From Mod Info, and it should automatically set up the addressables groups for you.