Make a Decal Follow the Camera in Game Engines
In this article
The most common way to make a decal follow the camera is to parent the decal actor to the camera component or use a script to update its position every frame. This method works for simple effects like blood splatters or dirt on a lens, but the process differs when you want the decal to stay stuck to a surface while the camera moves around it.
Check Your Scene Setup Before Parenting
Before you start moving objects, you need a clear understanding of how your scene hierarchy works. A decal is essentially a projected texture that casts an image onto whatever geometry it hits. If you parent a decal directly to a camera, the decal moves as the camera moves, which creates the illusion that the mark is stuck to the lens. You will need a camera component and a decal actor already present in your scene. Ensure the decal is pointing in the correct direction, as the projection axis determines where the image appears. Labels for these components can differ by version of the software you are using.
Check that your decal material is set to a mode that allows it to blend with the underlying surface. If the material is opaque, it will look like a floating square rather than a decal. You should also verify that the geometry the decal is hitting has a proper mesh. Decals cannot project onto empty space or certain types of trigger volumes. If you are working in a complex scene, make sure the decal is not being clipped by the camera's near-clip plane, which would make the decal disappear when the camera gets too close.
Parent the Decal to the Camera Component
- Open your character or camera blueprint and locate the camera component in the components list.
- Drag the decal actor from the world outliner and drop it onto the camera component to make it a child.
- Set the decal location to a small offset in front of the camera lens so it does not overlap with the camera's own origin.
- Rotate the decal so the projection arrow points forward, matching the camera's view direction.
- Adjust the decal size to cover the desired area of the screen, making it larger than the view frustum if you want it to cover the whole lens.
- Set the decal to move with the parent by ensuring the transform settings are set to relative rather than world space.
Update Decal Position with a Script
Parenting is a quick fix, but using a script gives you more control over how the decal behaves. For example, you might want the decal to fade in and out or shift slightly to simulate a liquid sliding down a lens. To do this, you create a logic loop that runs every frame. The script tells the decal to match the world location and world rotation of the camera. This prevents the decal from feeling too rigid and allows you to add offsets based on game events.
When writing this script, you should use the update function that triggers every frame. Fetch the current location of the camera and set the decal location to that same point. To avoid the decal flickering, ensure the update happens after the camera has finished its movement for that frame. If the decal is meant to be a screen-space effect, you can also consider using a post-process material, but a decal is better when you want the effect to interact with the actual 3D geometry in front of the lens.
Adjust Projection Settings for Better Alignment
A common problem is the decal appearing stretched or skewed. This happens because the projection angle is too shallow relative to the surface it is hitting. To fix this, you must adjust the rotation of the decal actor. The projection is a box or a cone; if the surface is parallel to the projection direction, the image will stretch toward infinity. Keep the projection perpendicular to the intended surface for the cleanest look.
You should also look at the decal size settings. If the projection box is too small, the decal will be cut off at the edges. If it is too large, you might accidentally project the image onto objects far behind the intended target. Check your software's viewport to see the projection bounds. You can scale the projection box to fit the specific area of the camera lens or the object you are tracking. If the decal is meant to follow the camera but stay on a wall, you will need to use a trace function to find the nearest surface and snap the decal to that point while keeping the camera as the reference.
Fix Decal Visual Glitches
When a decal follows a camera, it often encounters visual issues that break the immersion. One major problem is z-fighting, where the decal and the surface it is on occupy the same space, causing the image to flicker. To fix this, move the decal slightly away from the surface along its projection axis. This creates a small gap that prevents the engine from struggling to decide which surface to render on top.
Another issue is the decal appearing on the back side of objects. Most engines have a setting to disable backface projection. Ensure this is turned on so the decal only appears on the side facing the camera. If the decal looks blurry, check the texture resolution and the filtering settings of the material. If the decal is meant to be a smudge, a lower resolution might actually look more natural, but for a sharp logo or mark, you will need a high-resolution texture with a clean alpha channel.
Handle Decal Clipping and Culling
If the decal disappears suddenly as you rotate the camera, it is likely being culled by the engine. Culling happens when the engine thinks an object is not visible to the camera and stops rendering it to save performance. Since the decal is attached to the camera, its origin might be behind the camera's view, triggering the culling system. To fix this, you can increase the bounds of the decal actor or set it to never be culled in the actor settings.
You should also check the near-clip plane of your camera. If the decal is positioned too close to the lens, the camera will simply not render it. Move the decal further forward in the Z-axis of the camera's local space. This ensures the decal stays within the visible range of the camera while still appearing to be on the lens. If you are using a script to move the decal, you can add a check to ensure the decal always stays a minimum distance away from the camera origin.
Correct Common Setup Mistakes
Many people forget to set the decal to a relative transform, which causes the decal to stay at the world origin while the camera moves away. This results in the decal disappearing immediately upon starting the game. Always verify that the transform is relative to the parent camera.
Another mistake is using a standard material instead of a decal material. A standard material will create a solid 3D object that blocks the view, whereas a decal material uses a blend mode to project onto other surfaces. This causes the decal to look like a floating sheet of plastic rather than a paint mark. Ensure the material domain is set specifically to decal.
Some users try to use a UI element instead of a decal for lens effects. While a UI image is easier to place, it cannot interact with the 3D world. If your camera moves through a narrow gap, a UI element will stay perfectly flat, while a decal can be projected onto the walls of that gap, creating a more realistic sense of depth. Choose the decal method when the effect needs to feel like it exists in the physical space of the scene.
Resolve Decal Performance and Rendering Issues
If you have many decals following the camera, you might notice a drop in frame rate. Decals are more expensive to render than simple textures because they require the engine to calculate the intersection between the projection volume and the scene geometry. To optimize this, limit the number of active decals. You can use a system that destroys old decals and spawns new ones based on a timer or a specific event.
If the decal looks grainy, check the mipmap settings of the texture. Mipmaps help the engine choose a lower-resolution version of the texture when the decal is far away, but for a lens effect, you want the highest quality. You can set the texture to use a different mipmap filtering mode to keep the edges sharp. If the decal is flickering when moving quickly, ensure your script is updating in the late update phase of the engine loop, which happens after all physics and movement calculations are complete for that frame.