Skip to content

Creating prefabs to for machines

kremnev8 edited this page Aug 6, 2021 · 5 revisions

Creating prefabs to for machines

This is a detailed guide on how to create custom machines for DSP. This guide assumes you are familiar with unity, and have successfully followed unity dev environment setup guide.

Creating prefab

  1. Acquire a 3d model that can be imported into unity. It can even be a default cube.
  2. Add your model to scene and right-click on it and select unpack prefab. Ensure that top object of your model is an empty game object.
  3. Create a new prefab by dragging you empty gameobject into project folder. Open that prefab.
  4. Create BoxCollider on root object and set it to size. Copy it and paste as new. On that new collider set isTrigger
  5. Add scrips from DSP:
  • BuildConditionConfig. Describes certain requirements about a machine, like where it can be built. To fill land points or water points I suggest using gameobjects to determine position values.
  • SlotConfig. Defines everything related to selection. Copy your collider size and center to its fields. It also allows to define where belts or inserters can connect.
  • PowerDesc. Defines how this machines relates to power system. You can set it to be a power node, generator or consumer.
  1. Add empty game object called LOD and add LODModelDesc script to it. Here you need to define a few very important things.
  • Mesh collider: This is how game checks if your cursor is on mesh or not. Make a simple mesh that resembles your object loosely.
  • Mesh Data: This is where game is storing you ACTUAL model of the machine. Use AnimationBakerWindow from unity folder to create it.
  • Verta path: .Verta files contain baked animation data. You need this file only if your machines has animations. Use AnimationBakerWindow from unity folder to create it.
  • Lod Distance: How far from object do you need to be for it to become invisible (Vanilla buildings usually set it to values between 1000 and 5000)

Result

Once you done this your prefab should look like this:

Baking mesh and animations

  1. Exit of out prefab window and select you prefab in scene
  2. Go to Window->DSP Tools->Verta Animation Baker You should see AnimationBaker window popup
  3. If your mesh HAS animations select your animation clip, otherwise click No animations
  4. Click Bake