Creating Static Prefabs for Rogue Trader - WittleWolfie/OwlcatModdingWiki GitHub Wiki
N.B.: This guide relies on the use of MicroPatches v1.20+ for both the editor and the game. Things will not work correctly without both installed.
Ensure that you have set up the Unity template correctly, including install MicroPatches. At the time of writing, MicroPatches hasn't yet implemented the ability to instantiate game assets in the editor. Until that happens, you can download this script and place it in the WhRtModTemplate\Assets\Editor\ folder. This will add an additional menu called Importers that will allow you to spawn a small number of game assets like weapons and creatures in the editor for reference purposes (requires Game Services to be running).
From the Importers menu, select a vanilla asset that is closest in type to your custom asset. For example, Importers → Weapons → Ranged → Rifles → Sniper Rifle. The asset will be instantiated in the scene so that you can use it for reference. To prevent your view of the object being obscured, it is recommended to open the Gizmos menu (far right end of viewport toolbar) and uncheck FxLocator (you'll see these as a white square when enabled). You may need to adjust the viewport width to reveal this menu.
Additionally, you can add this script to your WhRtModTemplate\Assets\Editor\ folder, which will add some utilities for creating basic weapon prefab setups to the Modification Tools menu. These can be used to automate many of the steps below, although will still require some manual editing.
This guide is written under the assumption you will be creating a weapon prefab. You may need to make adjustments for other prefab types.
Asset Import and Configuration
Ensure you have prepared your assets ahead of time (this guide does not cover asset creation). At bare minimum this will be a mesh, typically exported as an FBX, and a texture set, typically comprising diffuse map, masks map, and normal map. TGA is the recommended texture format. Note that normal maps must be standard RGB tangent space (i.e. blue). If you are re-using game assets, ensure you deswizzle any normal map before importing. For custom normal maps, make sure to export them in OpenGL format (Y+). Texture resolution for vanilla models is typically 512x512. It is not recommended to exceed 2K for custom textures. It is assumed your textures will be power of 2/square.
Create your mod folder in the template if you haven't already done so. Import your assets into the Content folder. Select each texture in turn and adjust the following settings in the Inspector:
For the diffuse map, typically you will set Alpha Source to None, unless you explicitly require transparency and have an alpha mask for it. Under Advanced, set Filter Mode to Trilinear. Below that, switch from the Default tab to the Windows, Mac, Linux Settings tab, enable the Override checkbox and change Resize Algorithm to Bilinear. Click the Apply button.
For the masks map, untick the sRGB checkbox, set Alpha Source to None. Under Advanced, set Filter Mode to Trilinear. Below that, switch from the Default tab to the Windows, Mac, Linux Settings tab, enable the Override checkbox and change Resize Algorithm to Bilinear. Click the Apply button.
For the normal map, in the Texture Type drop-down, choose Normal map. Under Advanced, set Filter Mode to Trilinear. Below that, switch from the Default tab to the Windows, Mac, Linux Settings tab, enable the Override checkbox and change Resize Algorithm to Bilinear. Click the Apply button. Note that if you have imported a DirectX (Y-) normal map, you can check the Flip Green Channel checkbox to switch it to the required OpenGL (Y+).
Select your mesh. In the Inspector, switch to the Rig tab. For a truly static mesh you can set Animation Type to None and hit Apply. In the Animation tab, uncheck both checkboxes and hit Apply. In the Materials tab, change Material Creation Mode to None and hit Apply.
Somewhere in the Content folder, right click and in the pop-up menu choose Create → Material. Rename it whatever you like, although it is recommended to both use a standard prefix for all materials (like Mat_) and name it something suitably descriptive. This is especially important when you are planning on multiple texture variants of the same model.
Initial GameObject Creation
Prefabs are essentially just a collection of empty GameObjects that hold references to actual assets like meshes, materials, scripts, etc. They are similar in some respects to null/dummy objects in 3D modelling programs. The use of references allows a lot of flexibility with minimal performance overhead. For example, creating texture variants of a single mesh without the need to duplicate said mesh. Each prefab can reference the same source mesh and use a different material.
In the scene hierarchy, create a new empty GameObject. You can do this from the GameObject → Create Empty menu, or via the shortcut Ctrl + Shift + N. This is your prefab root. Rename it as appropriate. In the Inspector, zero out its X/Y/Z position co-ordinates in the Transform section. As you will have noticed if you have imported a vanilla game asset and/or perused the game bundles, these typically have a universal prefix that denotes their type. In the case of weapons, this is MSW_ in the case of melee weapons, PSW_ in the case of pistols, BSW_ in the case of rifles and similar medium ranged weapons, and HSW_ in the case of heavy ranged weapons. You can name your prefab whatever you wish, but it is useful to stick to the vanilla conventions for reasons of clarity. With the root GameObject selected, choose GameObject → Create Empty Child (Alt + Shift + N). Select the root object again and repeat as necessary. For ranged weapons, you'll typically need four child objects. Use the instantiated game asset as a guide for what your particular prefab will require.
One of these will be your primary mesh reference, one or more may be secondary mesh references (like a magazine for ranged weapons). These will typically be identified as such by their suffix. For example _weapon for the primary mesh and _ammo for the magazine secondary mesh. The rest are typically VFX locators for things like muzzle flash and ejection port shell casings. Name these as appropriate.
Adding GameObject Components
With your prefab hierarchy created, it's time to add the Components to each GameObject. The individual components hold the references to any assets along with relevant configuration settings.
Start with the root object. If you select the root of the vanilla asset and look in the Inspector, you'll see a collection of components in the vein of Equipment Offsets, Weapon Particles Snap Map, Occluded Object Highlighter Blocker Hierarchy, and Highlighter Blocker Hierarchy (will vary by object type). Starting with Equipment Offsets, click on the hamburger menu ( ⋮ ) on the far right and in the fly-out menu choose Copy Component. Select your prefab root object and in the Inspector click on the hamburger menu of the Transform section and in the fly-out choose Paste → Component As New. With this particular component you'll note it also automatically created two other components, since these are dependencies. Go back to the vanilla asset root object, click the hamburger menu of the Weapon Particles Snap Map component and in the fly-out menu choose Copy Component. Select your prefab root object and in the Inspector click on the hamburger menu of one of the components and choose Paste Component As New. You can change the order of the components via their hamburger menus using Move Up or Move Down on individual components as necessary.
Select the vanilla asset _weapon object. You'll see it has two components, a Mesh Filter and a Mesh Renderer. The former references the mesh, the latter references the material and allows the mesh to actually show up in-game. You can add these to your prefab's equivalent object either via the same copy and past approach as previously, or by simply clicking the Add Component button, typing in mesh in the search box to filter the results, and picking from the list. In either case, once they have been added, click on the browse button ( ⊙ ) in the Mesh slot of the Mesh Filter to open the asset browser. In the top righthand corner, drag the slider to the left to switch from thumbnails to list view (makes things easier to find), then double click your mesh. In the Mesh Renderer, you can simply drag and drop your material into the Element 0 slot of the Material list. Otherwise, use the asset browser in the same way as for the mesh. Depending on your 3D program of choice, you may find that your mesh is incorrectly oriented, or the wrong scale (or both). This can be addressed in the Transform section of the _weapon object. For example, users of 3DS Max may need to apply a -90° X rotation to their meshes. Scale can be adjusted in the same manner, although that can also be adjusted in the mesh directly via the Model tab in the Inspector (uniform scale only). Repeat this process for any secondary meshes, like a magazine.
For VFX locators, you need to physically position them in accordance with their function and the nature of your mesh. A _WeaponMuzzleFX locator, for example, is going to need to be placed in the front of the barrel muzzle and correctly centered. Likewise for the _WeaponShellFX, if appropriate (energy weapons don't use these), however this one also needs to be rotated correctly to ensure the VFX works in the intended manner. Refer to the rotation of the equivalent locator in the vanilla asset. After copying their components, you will need to open the asset browser in their Particle Map slot and select your prefab root object.
Prefab Finalisation and Variants
Once the GameObject configuration is complete and everything looks correct, you can finalise the creation of the your prefab by selecting the root object and dragging it into your Content folder. You can now delete the objects in the scene if you wish. You can resume editing of a saved prefab by either double clicking on it in the Content folder, or selecting it and clicking the Open button in the top right of the Inspector. This will open the prefab editor. You can exit this by clicking the < button on the top left. There's also a hamburger menu on the right with Save and Discard Changes options.
Your prefab is now complete and ready to be used in-game (once it's referenced in a blueprint).
If you wish to make variants of your prefab, for example different colours/textures, you can drag your prefab into the scene, change the name of the root object, and apply a new material in any Mesh Renderer components as necessary. When you drag this prefab back into the Content folder, you'll get a pop-up message asking whether you wish to create an original prefab or a prefab variant. Typically you would choose the latter, as this will reference the original mesh rather than duplicating it.
Non-Static "Static" Prefabs
Some vanilla weapons make use of dynamic physics objects, like cloth or rigid bodies. Unfortunately Owlcat have not equipped the template with whatever PBD editor they use on their end to create such assets, so for now those should be considered impractical to implement. They are at any rate outside the scope of this guide. If you have an interest in such assets, feel free to discuss it in the #mod-dev-technical channel of the official Owlcat Discord server.