Hello! Welcome back.
In our last session, we successfully built the data bridge between Unity and Rust. You created an FFI-safe data structure, passed the character creation form data to the Rust backend, and received a validation result. This was a critical step in integrating our core engine logic with the user-facing frontend.
This lesson shifts our focus back entirely to Unity. With the data pipeline established, it's time to bring the visual side of the character creator to life. Our goal is to achieve the next learning outcome: Preview the character's assigned 3D model in the creator scene.
We will set up a dedicated area in your character creation UI to display a 3D model, make it look professional with proper lighting, and even add some interactivity. This will transform your UI from a static form into a dynamic and engaging part of the game.

1. The Challenge: Rendering 3D Objects in a 2D UI
First, let's address the core technical challenge. Your character creator UI is built on a Unity Canvas, which is fundamentally a 2D system. Our character models, however, are 3D objects that exist in the 3D scene space. How can we "project" a live, 3D view of our character onto a 2D UI panel?
The solution is a powerful Unity feature called a Render Texture. A Render Texture is a special type of texture that isn't static; instead, it's updated in real-time by a camera's output. The workflow is:
- Point a Camera at a 3D object in your scene.
- Tell that camera to output its view to a Render Texture instead of the screen.
- Display that Render Texture on a UI element, typically a
Raw Image.
This creates a "live window" from your UI into the 3D world.
To get a formal definition and see the properties you can adjust, please read the introductory sections of Unity's official documentation on Render Textures.
Render Texture - Unity - Manual
The Unity Manual provides a concise explanation of what a Render Texture is and how it's used. This will give you the foundational knowledge before we jump into the implementation.
Please read the introduction at the very top of the page and the 'Example' section. This will familiarize you with the concept and the basic steps involved.
2. Building the Character Preview
Now let's get hands-on and implement this. We will create the UI panel, set up a dedicated camera and model, and link them all with a Render Texture. The following video provides a complete walkthrough of this process.
Create a CHARACTER CREATION SCREEN In Unity - EP. 1 Character Preview
This video from Sebastian Graves, 'Create a CHARACTER CREATION SCREEN In Unity', demonstrates the entire process of setting up a character preview window. We will follow its steps closely.
Watch from 07:26 to 11:10. This segment covers: Dragging a character model into the scene. Creating a separate camera just for the preview. Creating the Render Texture asset and linking everything together. Follow these steps in your own project. You can place the character model and the new camera anywhere in your scene, as long as they are away from your main game camera.
Step-by-step implementation guide:
- Prepare your Scene:
- Find a 3D character model to use for the preview. A good starting point is a free character from Mixamo, as recommended in the course outline. Download one with its texture and import it into your Unity project.
- Drag the character prefab into your Character Creator scene. Position it somewhere out of the way (e.g., at coordinates
100, 0, 0).
- Create the Preview Camera:
- Create a new Camera (
GameObject > Camera). Let's name itCharacterPreviewCamera. - Position this camera so it has a good view of your character model.
- In the Camera component settings, change Clear Flags to
Solid Colorand set the background color to something neutral (or transparent if you prefer).
- Create a new Camera (
- Create the Render Texture:
- In your Project window, create a new Render Texture (
Assets > Create > Render Texture). Name itCharacterPreviewTexture. You can set itsSizeto something like 1024x1024. - Select your
CharacterPreviewCameraand drag theCharacterPreviewTextureinto its Target Texture field.
- In your Project window, create a new Render Texture (
- Display on the UI:
- In your character creator UI, find or create the panel where you want the preview to appear.
- Add a
Raw ImageUI element to this panel (GameObject > UI > Raw Image). - Select the
Raw Imageand drag yourCharacterPreviewTextureinto its Texture field. - Resize and position the
Raw Imageas needed. You should now see your character model rendered inside the UI!
3. Adding Interactivity: Model Rotation
A static preview is good, but an interactive one is better. Let's allow the user to rotate the character by clicking and dragging the mouse. This gives them a full 360-degree view of their creation.
We'll create a simple C# script to handle this. You can attach this script to an empty GameObject that will serve as the pivot point for your character model.
Create a CHARACTER CREATION SCREEN In Unity - EP. 1 Character Preview
The same video also provides a great tutorial for scripting the rotation.
Watch from 13:11 to 19:52. The video explains how to create a C# script that reads mouse movement on the X-axis and uses it to rotate the character. Pay close attention to the hierarchy setup: the script rotates a parent object, and the character model is a child of that object.
Here is a summary of the script and logic. Create a new C# script named CharacterRotator and add it to a new empty GameObject in your scene called CharacterPivot. Make your character model a child of this CharacterPivot object.
using UnityEngine;
using UnityEngine.InputSystem; // Make sure you have the Input System package installed
public class CharacterRotator : MonoBehaviour
{
[SerializeField] private float rotationSpeed = 10f;
private bool isRotating = false;
// This method is called by the PointerDown event from an Event Trigger
public void OnPointerDown()
{
isRotating = true;
}
// This method is called by the PointerUp event from an Event Trigger
public void OnPointerUp()
{
isRotating = false;
}
void Update()
{
// Only rotate if the mouse button is held down over the preview image
if (isRotating)
{
// Get horizontal mouse movement
float mouseX = Mouse.current.delta.x.ReadValue();
// Rotate the pivot object around the Y-axis
transform.Rotate(Vector3.up, -mouseX * rotationSpeed * Time.deltaTime);
}
}
}
To make this script work:
- Attach the
CharacterRotatorscript to yourCharacterPivotGameObject. - On your
Raw ImageUI element, add an Event Trigger component. - Add two new event types:
PointerDownandPointerUp. - For the
PointerDownevent, drag yourCharacterPivotGameObject into the object field and selectCharacterRotator > OnPointerDown. - For the
PointerUpevent, do the same but selectCharacterRotator > OnPointerUp.
Now, when you enter Play mode, you should be able to click and drag on the Raw Image to rotate your character model.
4. Professional Polish: Lighting the Scene
Your character preview works, but it might look a bit flat. Good lighting is essential for making 3D models look appealing. A standard and highly effective technique used in film, photography, and game development is three-point lighting.
It consists of three main lights:
- Key Light: The primary and brightest light source, positioned to one side.
- Fill Light: A secondary, less intense light positioned on the opposite side to "fill in" the shadows created by the key light.
- Back Light (or Rim Light): A light placed behind the subject to create a subtle bright outline (rim), separating the subject from the background and adding depth.
Showcase your work with lighting
This Unity Learn article provides an excellent, practical guide to three-point lighting. It explains the purpose of each light and challenges you to set it up yourself.
Read the sections 'Three-point lighting', 'Review the studio lighting setup', and 'Customize your own product lighting study'. Focus on understanding the role of the key, fill, and back lights. Then, try to replicate this setup for your character model.
Your Task:
In your scene, add three Spot Light or Directional Light GameObjects. Position them around your character model to create a three-point lighting setup. Experiment with their color, intensity, and angle to see how they affect the final look of your character in the preview window. This is a great opportunity to develop an eye for presentation.
5. Thinking Ahead: Swapping Character Models
Right now, we have one model hardcoded into our preview. A full character creator will need to support different models (e.g., masculine/feminine body types, different species). How do we swap the character's visual mesh while keeping the same underlying skeleton (armature) and animations?
This involves changing three key things on your character's GameObject at runtime:
- The Skinned Mesh Renderer's mesh.
- The
Skinned Mesh Renderer's reference to the skeleton's bones. - The Animator's
Avatar, which is a map of the bones to a humanoid rig.
You don't need to implement this right now, but understanding the concept is crucial for your project's architecture.
How to SWAP your Character! (Change Mesh Visual, Same Animations, Controller)
Code Monkey's video 'How to SWAP your Character!' explains this process very clearly. Understanding this now will save you a lot of refactoring time later.
Watch from 00:20 to 03:59. This covers the three core components you need to change and highlights a very common pitfall related to bone naming. Absorb the concept for now; we will implement the actual swapping logic in a future lesson when we add more character options.
Conclusion
Excellent work! You have successfully created a dynamic, interactive preview for your character creator. This adds a huge amount of polish and brings the game one step closer to feeling like a complete experience.
Key Takeaways:
- Render Textures are the standard Unity technique for rendering a 3D scene view onto a 2D UI element.
- The setup involves a dedicated Camera, a Render Texture asset, and a Raw Image on the UI Canvas.
- You can add interactivity, like model rotation, by capturing UI events (
Event Trigger) and using mouse input to rotate a parent pivot object. - Three-point lighting (Key, Fill, Rim) is a fundamental technique for professionally lighting a subject and making it stand out.
- Swapping character models involves changing the mesh, bone references, and Avatar at runtime.
You have now completed the entire visual and data-entry portion of the character creator. In the next lesson, we'll close the loop by implementing the final step: Save a validated character profile to a dedicated JSON file upon creation. This will take the validated data from Rust and persist it to disk, creating a permanent character that can be loaded into the game world.