Survivalist: Invisible Strain Guide

Importing new models using Unity Asset Bundles for Survivalist: Invisible Strain

Importing new models using Unity Asset Bundles

Overview

How to add new types of buildings etc to your mod

How to import a blue or possibly red cube into the game

The first thing you need to do – if you haven’t already – is follow this guide to create your own Story mod.

Next, download Unity[unity3d.com]. I’m using Unity 2020.1.2f1. (I’m not sure if it matters if you use a different version)

In Unity, start a new project (selecting 3D when it asks you which template to use). I’ve create a quick Example Project[www.dropbox.com] as a guide, if that helps.

Create the prop you want to import and make it a prefab. This isn’t a Unity tutorial so I won’t explain in depth how to do that, but presumably you’ll be creating a model in Blender[www.blender.org] or similar. Put that and all your textures in the Assets folder of your Unity project and then create a prefab from it. As a test, you can try just creating a cube. In the scene Hierarchy pane click + and select 3D Object/Cube. Drag it into the Assets folder to create a prefab.

Make sure your model has collision detection! Survivalist doesn’t have full 3d collision detection for stuff like walking around the world but it is used for raycasts to check if AI can see people through your prop, or if you can shoot through it. It’s also used for ragdolls and objects you throw. To give your model collision detection, add components: Box Colliders, Sphere Colliders, or Mesh Colliders. If you’re using a mesh collider, make sure it’s not a massively complicated mesh – go easy on the vertex count.

Next you need to add the prefab, and any models, textures or materials it uses, to an asset bundle, following the Unity Asset Bundle Workflow[docs.unity3d.com]:

  • Select the Asset you want to assign to a bundle from your Project View.
  • Examine the object in the Inspector
  • At the bottom of the Inspector, there is a section to assign AssetBundles and Variants. Use the left-hand drop down to assign the AssetBundle, and the right-hand drop down to assign the variant.
  • Click None on the left-hand drop to reveal the currently registered AssetBundle names.
  • Click New to create a new AssetBundle
  • Type in the desired AssetBundle name.


Create a folder called Editor in the Assets folders, and place a script with the following contents in the folder:

using UnityEditor; using System.IO; public class CreateAssetBundles { [MenuItem(“Assets/Build AssetBundles”)] static void BuildAllAssetBundles() { string assetBundleDirectory = “Assets/AssetBundles”; if(!Directory.Exists(assetBundleDirectory)) { Directory.CreateDirectory(assetBundleDirectory); } BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows); } }

This script creates a menu item at the bottom of the Assets menu called Build AssetBundles that executes the code in the function associated with that tag. When you click Build AssetBundles a progress bar appears with a build dialog. This takes all the Assets you labeled with an AssetBundle name and places them in “Assets/AssetBundles”.

Find the “AssetsAssetBundles” folder in Windows Explorer and copy the asset bundle and the manifest file – in my case “cube” and “cube.manifest”. In your Survivalist: Invisible Strain story mod folder, create a subdirectory called AssetBundles and paste them in there.

Run Survivalist: Invisible Strain and go to Editor / Your Story / Edit Props. Click Create New and name it Cube. In the Model[0] dropdown you should be able to find your prefab – in my case assets/cube.prefab.


Set up the prop with some appropriate settings and you should now be able to place it in the game using the F8 debug menu and going to Prop Spawner.

Some notes about the prop editor:

  • The Category field defines where it will appear in the F8 Prop Spawner menu
  • The Extents Min and Extents Max fields define how big it is in terms of tiles. e.g. if Extents Min is -1, -1 and Extents Max is 1, 1, the prop will be 3×3 tiles.
  • The Type Name defines its behaviour, e.g. select Building if you want people to be able to enter it.
  • In my example I created two materials, a blue and a red one, and imported them both along with the cube prefab. I selected them in the Material Variations fields. This means the cube will randomly choose the blue or red variation when it is spawned. Similarly if you selected more than one Model in the Models dropdowns it would pick one at random.

Materials and Snow

Every prop in the world of Invisible Strain needs to support snow, which is done using a custom shader. This means you can’t just use the standard Unity materials, you’ll need to use one with the “Custom/StandardSnow” shader I wrote which adds snow to everything – if it’s facing upwards – based on some global values such as _SnowAmount.

This means you’ll need to add my snow shader files to your project. In fact there’s 4 of them:

StandardSnow.shader
StandardFloraSnow.cginc
FloraCommon.cginc
CustomTerrainCommon.cginc

Download my Example Unity Project[www.dropbox.com] to get them.

Then, when you create a new material, select the Custom/StandardSnow shader at the top. Or if you have existing materials, convert them all to use that. (Unless of course you really don’t want your stuff to be affected by snow, which might be the case with stuff that’s under a shelter or something).

Weapon Models

What if you want to add a new model for a gun, melee weapon, or other piece of equipment? First, in the game’s Editor menu go to Edit Equipment, and Create New. Enter a name. Then set up all the fields – you might want to look in BaseStory for comparison against other similar types of equipment. Make sure to tick the Can Be Equipped field.

The Type Name defines what kind of special behaviour the equipment will have, and what fields will be available. Let’s use the Magnum mod as an example – the Type Name is set to Pistol.


So, just like you did with the buildings, set up a model of a gun or whatever your equipment is in Unity and add it to an asset bundle, and put that in the AssetBundles folder of your mod. Then run the game and, in the Edit Equipment screen, find the Equipped Model Name field and you should be able to set that to your asset’s name in the dropdown.


This means your model will now appear attached the character when they equip that piece of equipment. But it might be a crazy scale – either enormous or tiny – or it might be offset from their hand by a huge distance. You need to set it up to have the correct position, rotation and scale. To do this, back out of the editor and start a New Game, selecting your mod.

Once the world has loaded, press F8 to open the debug menu, go to Equipment Spawner, and find your equipment at the bottom of the list. Spawn one and equip yourself with it. Hopefully you will now be able to see it, but it may be hidden due to having a small scale or something. In the debug menu go to EquippedModelEditor and start playing around with the Scale until you can see it.

You’ll probably want to set Bone to RightHand so it’s attached to that hand. Equipped Anim controls what set of animations they use when holding it, for the Magnum we set that to Pistol. Once you’ve set those you can play with the Position, Rotation and Scale until it fits as closely as possible into their hand.


Some of the other values are a little more esoteric-looking – when the player aims a gun, some IK happens on top of the base animation to set their hand positions. If you’re making a gun you’ll probably want to copy these values from other, existing guns. And if you’re not, you can probably ignore them.

You can also put sounds in your asset bundles and override the default gun firing and reloading sounds – at the bottom of the Edit Equipment screen there are some drop-downs for this.

Clothing Models

You can also make your own clothing models – see the Trilby Hat mod for an example, and download this sample project[www.dropbox.com] which includes the character model in Blender, which you’ll need to attach your clothing to.

In Trilby.blend you’ll find a Male and Female character model, and an armature and a Trilby hat model for each. They are all on different layers, use the layers control to show them all, and the Outliner to see all the components of the scene.


If you select the Trilby models you’ll see they have Armature modifiers, attaching them to UMA_Female_Rig and UMA_Male_Rig. Select the Weight Paint tool and you can see all the vertices are attached to the Head bone.


So to add a clothing model, you’ll need to make a copy of this .blend file, import your models (a male one and a female one), add Armature modifiers attaching them to the skeletons, and use weight paint to attach them to the appropriate bones. Then save your blender file and put it in the Assets folder of your Unity project.

In Unity, select your blender file and drag it into the scene. Right click it and select Prefab -> Unpack Completely. You’ll want to make a prefab for the male model and a prefab for the female. Delete all the body part models (they are just for your reference in Blender). And delete the model and rig of the other gender. Keep the rig and model of the gender your are making (i.e. Trilby_Female and UMA_Female_Rig).


Make a prefab out of this by dragging it onto the Assets folder. Then do the same for the other gender. Set your prefabs to go into your asset bundle, as described earlier in this guide, build the asset bundle and copy it to your mod’s AssetBundles folder.

Run the game, edit your mod, go to Edit Equipment, and Create New. You’ll want to set the Clothing Type field (e.g. for the Trilby this is set to Hat). Then set the Male Mesh Name and Female Mesh Name fields – the models in your asset bundle should be available in these drop-downs. And you’re done!

SteamSolo.com