top of page
Search
Writer's picturecalvin kumagai

Decal King Tutorial

Updated: Jan 9, 2021

Since we just released our first Unity package, "Decal King" I thought it would be nice to provide a short tutorial for it. For you more visually minded folks out there, I'll leave the video form of this tutorial at the bottom of this article.


For this tutorial I'll walk you through step-by-step how I set up the spray paint demo scene that comes prepackaged with Decal King. This should demonstrate how easy Decal King is to set-up in your own projects.

Spray can spraying graffiti with "Decal King"

1. Setup Your Scene With Mesh Colliders

Decal King functions by generating a mesh with information gathered from a collider. This allows Decal King to function independently of your render pipeline. Therefore any surface you want to cast decals against should have a mesh collider attached.


Mesh collider component in Unity

2. Drop the Player Object in the Scene

I'm going to assume that you know how to set up a player controller in Unity. It's not really related to Decal King. If you need to learn about very simple FPS controllers, Brackeys has a good tutorial already: https://youtu.be/_QajrabyTJc


The only thing noteworthy about my player character is that it has it's spray can attached to it's camera.

Unity player controller holding spraycan

Make sure that your player character is set to the "Ignore Raycast" layer. If you don't do this you will have issues with the player casting decals against themselves unintentionally.

Player controller set to "Ignore Raycast" layer


3. Attach Decal King Prefab to Player

Decal King comes with 3 ready-made prefabs.

Main prefabs for Decal King in Unity editor

Stationary Decal Forward

Stationary decals are generated at the beginning of runtime. The should never change after the game starts. These might be used for static environment details.


Constant Decal Down/Constant Decal Forward

Constant Decals update during runtime. Therefore, they can be used for things such as the red circle in the spray can scene that indicates where the player is aiming. The only difference between these two is the direction they point by default. "Constant Decal Down" might be better suited for an RTS or MOBA style game. For our purposes I'll use the "Constant Decal Forward"


Just drag the "Constant Decal Forward" prefab onto the player's camera in the hierarchy, so that it is in sync with the spray can's movement. We will use this to set up that red targeting ring you can see in the image of the demo scene.


"Constant Decal Forward" prefab in Unity

FYI, the Decal King prefabs have an arrow attached to it that indicates the direction a decal will be cast. They are very small as to not obstruct your scene. Of course, they will disappear during runtime. If you have trouble seeing them, select the prefab and hit Shift+F to get a full view of it.

Close up of "Constant Decal Forward" prefab in Unity

WARNING: Do not rotate the arrow directly. Adjust the direction through the base prefab.


4. Adjust Settings Accordingly

If you press play, you should see that the red targeting ring already works pretty well. There are some key settings that you can edit to improve its quality. Below are the settings I used to create the red targeting ring in the demo scene.

Decal King settings menu in Unity inspector

Decal Vertices X/Y

Increasing the resolution of the mesh generated for decals is a reliable way to improve the results of decals. If your decal is not conforming to a surface well, try increasing these values. FYI, if the X/Y values are not equal, the decal will be stretched.


Max Variance

This sets the maximum distance a vertex can be drawn from the previous vertex. If its too low small curves in the surface will cause the decal to be cut off. If its too high the decal can stretch to insane levels. I got pretty good results with a value of 1.


Lock Plane

Prevents severe distortion of the decal. I enabled it for the targeting ring since I am more concerned with its shape being retained rather than it conforming to surfaces perfectly.


Hover If Initial Raycast Fails

Enabling this directs Decal King to draw a decal even if there are no surfaces in its casting range. This is exactly what I want for the aiming ring, so I enabled it.


Height Offset

Most decals should have this set extremely low (Like .01) in order to have it appear as if its stuck to the walls surface. However, I want the targeting ring to always appear above other decals, so I increased the value to 1.


With these settings the targeting ring works great!

Spray can with targeting ring set-up

5. Set Up Decal Caster

To give ourselves the ability for us to shoot graffiti tags onto walls we will need to add a second "Constant Decal Forward" prefab to our player. We just need to parent it to the camera in exactly the same way we did the first one. For this one almost all the default settings should work well. We just need to change 4 settings.


Change the Mode to "Decal Caster"

"Decal King" in "Decal Caster" mode

"Decal Caster" mode allow decals to be triggered by an event such as a button press.


Assign a Trigger

"Decal King" "Decal Caster Options" menu

Assign a Custom Input as whatever button will trigger your decal. Then assign a button trigger condition. I don't want more decals to be drawn when the button is held down, so I will set the trigger condition to be "Button Down"


Assign Decal List

"Decal King" possible decals list

You can assign however many decals you want to a Decal Caster. Decal King comes with 6 graffiti decals, so I will set the list of possible decals to a size of 6. After I assign each material to the list Decal King will choose one of these at random when casting.


Set Up Randomize Rotation

At this point, Decal King should already be able to cast graffiti without any issues. However, all the decals will be perfectly horizontal. Enabling randomize rotation will make our decals look a lot more natural when placed.

"Decal King" "Decal Mesh Options" menu

I enabled Randomize Rotation and set the range to be from -30 to 30 and got pretty good results.


Now we're finished!


Spray can spraying graffity onto walls with "Decal King"

Thank you for looking at our tutorial. If questions, please feel free to reach out.


Check Out Decal King on the Unity Asset Store! Purchases supports what we do at Fun Freighter Games.



198 views0 comments

Recent Posts

See All

Comments


bottom of page