Unturned

Unturned

Not enough ratings
Custom Physics Materials with Impact Decals
By JienSultan
This guide will teach you how to create custom Physics Materials with an Impact Effect that has it's own Decal.
   
Award
Favorite
Favorited
Unfavorite
What are Physics Materials?
Physics materials define the physical properties of surfaces. They dictate how players and rigidbodies interact with those surfaces, such as:
  • Friction: How slippery or grippy a surface is.
  • Bounciness: How much an object will bounce upon impact.
  • Sound Effects: The sounds produced when interacting with surfaces.
Asset File
Setting up an Asset File for your custom Physics Material is easy.

Refer to the Documentation[docs.smartlydressedgames.com] for extra information.



"Metadata" { "GUID" "your-generated-guid" "Type" "SDG.Unturned.PhysicsMaterialAsset, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" }

  • GUID: A unique identifier for your asset. This should be generated with https://guidgenerator.com/ and should be kept unique for each asset.
  • Type: Defines the type of asset. In this case, it's a physics material from SDG.Unturned.



"Asset" { "UnityNames" [ "your-material-name" ] "Fallback" "fallback-effect-guid" "WipDoNotUseTemp_BulletImpactEffect" "your-effect-guid" // Snow_NoAudio "TireMotionEffect" "9fc986e74c6c4ebbac86bc41791159e5" }

  • UnityNames: The names associated with the Unity asset. This is how the game recognizes the physics material.
  • Fallback: References a fallback effect. If your custom effect can't be found, the game will use this as a substitute.
  • WipDoNotUseTemp_BulletImpactEffect: References your Effect with the Decal to put on a surface.
  • TireMotionEffect: References an effect that will be applied when tires move over this surface.

Requirements

The example assets provided do not include the vanilla Decal Diffuse shader. To implement custom decals, we need to create a dummy shader that includes the appropriate data values.

Shader "Decal/Diffuse" { Properties { _MainTex ("Diffuse", 2D) = "white" {} _Cutoff ("Cutoff", Float) = 0.5 } SubShader { Tags { "RenderType" = "Opaque" } LOD 200 Stencil { Ref 1 WriteMask 1 Pass Replace } CGPROGRAM #pragma surface surf Standard #pragma target 3.0 sampler2D _MainTex; struct Input { float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutputStandard OUT) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex); OUT.Albedo = c.rgb; OUT.Alpha = c.a; } ENDCG } FallBack "Diffuse" }


You will also need a Decal Script extracted from the game's Assembly-CSharp.dll.
Don't worry, I got you:

using UnityEngine; namespace SDG.Unturned { public enum EDecalType { DIFFUSE } public class Decal : MonoBehaviour { public EDecalType type; public Material material; public bool isSelected; public float lodBias = 1f; protected BoxCollider box; } }


This plane should be 0.5m x 0.5m, and facing up.
Effect Prefab



The effect prefab should have the following setup:

Now of course, you’re gonna have to apply the dummy shader to the material that is put in the mesh renderer of the Effect Prefab.
You should also create some sort of particle system for the Effect Prefab, so it gives some sort of response to you interacting with surfaces which have your custom physics material applied to their colliders.

After you completed setting up your Effect prefab, bundle it with the Bundle Tool and do not masterbundle it.

Your effect's dat file should look something like this:
GUID your-effect-guid Type Effect ID your-effect-id Preload 4 Exclude_From_Master_Bundle
Shader Data

Now you have to replace the dummy shader's data inside your asset bundle with the data from the vanilla decal shader. We will be using UABEAvalonia[github.com] for this.

Once you've downloaded UABEA;
  1. Drag core.masterbundle into the UABEA window to open it.
  2. Once a new window pops up, decompress the bundle to Memory. This will take a minute or two.
  1. Click Info.
  2. Now find the shader file with the Path ID of -5917583366160842773. This value can change with any update on the masterbundle file. if you can't find it, go through every shader by clicking on View Data until you find it.
  3. Select it, and Click on Export Dump.
Now reopen UABEA.
  1. Drag your .unity3d file into the UABEA window to open it.
  2. Once a new window pops up, decompress the bundle to Memory.
  3. Click Info.
  4. Now find the only shader file in your bundle.
  5. Select it, and Click on Import Dump.
  6. Select the Dump file we just exported.
  7. In the top left, click on File, Save.
  8. Close this window, and Save again in the smaller UABEA window.

Done.
Usage
To use your newly created Physics Material, simply create a new physics material in Unity and give it the same name you put under UnityNames in your asset file.
Then just simply apply it to any object’s mesh colliders or box colliders.