Configuring the part in Unity

From KSP 2 Modding Wiki
Revision as of 14:24, 13 January 2024 by Munix (talk | contribs)

The following page will guide you through setting up a new part inside Unity.

Configuring the part in Unity

Prerequisites
Setting up Unity
Modeling the mesh in Blender
Texturing the mesh in Substance 3D Painter
Preparing the mesh for Unity
Useful links (may contain outdated information)
Tutorial for creating a part in Unity: https://luxstice.notion.site/Tutorial-My-First-Part-5f0cf456d7f4443d8c92658c7cc58314
Tutorial for configuring a part in Unity: https://www.youtube.com/watch?v=9fQg-oMqcH8

Setting up the scene

  1. Open Unity Hub.
  2. Open the Unity project.
  3. Click on the three dots in the Hierarchy menu then “Add a new scene”.
  4. Right-click on the scene > Save Scene.
  5. Save the scene in the Asset folder of the Unity project.
  6. In the Asset folder, create a folder for the mod.
  7. In this folder, create the “Materials” and “Parts” folders. This is just to keep the folder well organized.
  8. Delete the camera and light and import the meshes and textures into the corresponding folders.
Good practice for organizing the Assets folder
Assets
|
\-Modname
  |
  \-Parts
    |
    \-(separate folders for the type of parts)
      |
      \-Folder for each part
  |
  \-Materials

Associating textures to the meshes

  1. Create a material in Unity for each material in Substance Painter (right-click on the project window > Create > Material)
  2. Select all materials. In the Inspector window, in Shader, select KSP > Parts > Paintable.
  3. For each material, assign the textures to the Albedo, Metallic, Normal, Emissive and Paintable channels.
  4. For Normal channels, click the “Fix Now” button.
  5. For each mesh, assign the materials to the corresponding locations. Click on “Apply”.

Adding meshes to the scene

  1. Create an Empty GameObject. Let's name it myMod_myPart. The name must be unique to any part in KSP2, including other mods.
  2. Set its position to 0;0;0.
  3. Create another empty object as a child of this object and call it model.
  4. Drop the mesh as a child of model.
  5. Use the “Transform” panel to optionally modify the position, rotation and size of the mesh.
  6. Right click on the mesh > Prefab > Unpack completely.
  7. Select all colliders.
  8. In the Inspector window:
    • Delete the “Mesh Renderer” component.
    • Click on Add Component > Mesh Collider.
    • Check “Convex”.
  9. Repeat the operation for all meshes.

Note: Materials should not have shaders.

Configuring the part data

Follow these instructions: Configuring the core part data.

Configuring the addressables

Creating the addressables

  1. If you followed the "Configuring the core part data" instructions linked above, you should have an addressables group set up for your mod with your prefab and JSON files already added.
  2. Next, select all icon images in the Asset folder and check "Addressable" in the Inspector window.